Repository: edgedb/edgedb

Issue:
InternalServerError when describing a function that doesn't exist
- EdgeDB Version: 1.0-rc.5
- OS Version: wsl2 on windows 10

Steps to Reproduce:
`describe function lol;`


Discussion:

Resolving patch:
diff --git a/edb/edgeql/compiler/stmt.py b/edb/edgeql/compiler/stmt.py
--- a/edb/edgeql/compiler/stmt.py
+++ b/edb/edgeql/compiler/stmt.py
@@ -37,6 +37,7 @@
 from edb.schema import functions as s_func
 from edb.schema import links as s_links
 from edb.schema import properties as s_props
+from edb.schema import modules as s_mod
 from edb.schema import name as s_name
 from edb.schema import objects as s_obj
 from edb.schema import objtypes as s_objtypes
@@ -803,6 +804,13 @@ def compile_DescribeStmt(
             itemclass = objref.itemclass
 
             if itemclass is qltypes.SchemaObjectClass.MODULE:
+                if not ctx.env.schema.get_global(
+                        s_mod.Module, objref.name, None):
+                    raise errors.InvalidReferenceError(
+                        f"module '{objref.name}' does not exist",
+                        context=objref.context,
+                    )
+
                 modules.append(s_utils.ast_ref_to_unqualname(objref))
             else:
                 itemtype: Optional[Type[s_obj.Object]] = None
@@ -893,6 +901,13 @@ def compile_DescribeStmt(
                 if not items and last_exc:
                     raise last_exc
 
+                if not items:
+                    raise errors.InvalidReferenceError(
+                        f"{str(itemclass).lower()} '{objref.name}' "
+                        f"does not exist",
+                        context=objref.context,
+                    )
+
             verbose = ql.options.get_flag('VERBOSE')
 
             method: Any


Test patch:
diff --git a/tests/test_schema.py b/tests/test_schema.py
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -8445,6 +8445,55 @@ def test_schema_describe_schema_02(self):
             explicit_modules=True,
         )
 
+    def test_schema_describe_missing_01(self):
+        with self.assertRaisesRegex(
+                errors.InvalidReferenceError, "function 'lol' does not exist"):
+
+            self._assert_describe(
+                """
+                # nothing, whatever
+                """,
+
+                'describe function lol',
+
+                """
+                # we'll error instead of checking this
+                """,
+            )
+
+    def test_schema_describe_missing_02(self):
+        with self.assertRaisesRegex(
+                errors.InvalidReferenceError, "module 'lol' does not exist"):
+
+            self._assert_describe(
+                """
+                # nothing, whatever
+                """,
+
+                'describe module lol',
+
+                """
+                # we'll error instead of checking this
+                """,
+            )
+
+    def test_schema_describe_missing_03(self):
+        with self.assertRaisesRegex(
+                errors.InvalidReferenceError,
+                "object type 'std::lol' does not exist"):
+
+            self._assert_describe(
+                """
+                # nothing, whatever
+                """,
+
+                'describe type lol',
+
+                """
+                # we'll error instead of checking this
+                """,
+            )
+
 
 class TestCreateMigration(tb.BaseSchemaTest):