Repository: edgedb/edgedb

Issue:
InternalServerError when user does not provide an object type
<!-- Please search existing issues to avoid creating duplicates. -->

<!--
For the EdgeDB Version: run `edgedb query 'select sys::get_version_as_str()'` from your project directory (or run `select sys::get_version_as_str();` in the EdgeDB interactive shell).
For the EdgeDB CLI Version: Run `edgedb --version` from anywhere
-->

- EdgeDB Version: 2.14+bc002ae
- EdgeDB CLI Version: EdgeDB CLI 2.3.1+5d93f42
- OS Version: Mac OS X Monterey

Steps to Reproduce:

In the REPL:
```
EdgeDB 2.14+bc002ae (repl 2.3.1+5d93f42)
Type \help for help, \quit to quit.
edgedb> insert { oops := "imessedup" };
edgedb error: InternalServerError: 'NoneType' object has no attribute 'context'
  Hint: This is most likely a bug in EdgeDB. Please consider opening an issue ticket at https://github.com/edgedb/edgedb/issues/new?template=bug_report.md
  Server traceback:
      Traceback (most recent call last):
        File "/Users/delannmt/Library/Application Support/edgedb/portable/2.14/lib/python3.10/site-packages/edb/server/compiler_pool/worker_proc.py", line 55, in worker
          res = meth(*args)
        File "/Users/delannmt/Library/Application Support/edgedb/portable/2.14/lib/python3.10/site-packages/edb/server/compiler_pool/worker.py", line 160, in compile
          units, cstate = COMPILER.compile(
        File "/Users/delannmt/Library/Application Support/edgedb/portable/2.14/lib/python3.10/site-packages/edb/server/compiler/compiler.py", line 2524, in compile
          unit_group = self._compile(ctx=ctx, source=source)
        File "/Users/delannmt/Library/Application Support/edgedb/portable/2.14/lib/python3.10/site-packages/edb/server/compiler/compiler.py", line 2049, in _compile
          return self._try_compile(ctx=ctx, source=source)
        File "/Users/delannmt/Library/Application Support/edgedb/portable/2.14/lib/python3.10/site-packages/edb/server/compiler/compiler.py", line 2075, in _try_compile
          statements = edgeql.parse_block(source)
        File "/Users/delannmt/Library/Application Support/edgedb/portable/2.14/lib/python3.10/site-packages/edb/edgeql/parser/__init__.py", line 77, in parse_block
          return parser.parse(source)
        File "/Users/delannmt/Library/Application Support/edgedb/portable/2.14/lib/python3.10/site-packages/edb/common/parsing.py", line 420, in parse
          self.parser.token(token)
        File "/Users/delannmt/Library/Application Support/edgedb/portable/2.14/lib/python3.10/site-packages/parsing/lrparser.py", line 57, in token
          self._act(token, tokenSpec)  # type: ignore
        File "/Users/delannmt/Library/Application Support/edgedb/portable/2.14/lib/python3.10/site-packages/parsing/lrparser.py", line 94, in _act
          self._reduce(action.production)
        File "/Users/delannmt/Library/Application Support/edgedb/portable/2.14/lib/python3.10/site-packages/parsing/lrparser.py", line 124, in _reduce
          r = self._production(production, rhs)
        File "/Users/delannmt/Library/Application Support/edgedb/portable/2.14/lib/python3.10/site-packages/parsing/lrparser.py", line 138, in _production
          r = production.method(sym, *rhs)
        File "/Users/delannmt/Library/Application Support/edgedb/portable/2.14/lib/python3.10/site-packages/edb/common/context.py", line 262, in wrapper
          result = func(*args, **kwargs)
        File "/Users/delannmt/Library/Application Support/edgedb/portable/2.14/lib/python3.10/site-packages/edb/edgeql/parser/grammar/expressions.py", line 280, in reduce_Insert
          context=subj_path.context)
      AttributeError: 'NoneType' object has no attribute 'context'
```

Although this is a clear mistake by the user, a better error message would really help identify the problem when such a typo is nested somewhere in a long query command.



Discussion:

Resolving patch:
diff --git a/edb/edgeql/parser/grammar/expressions.py b/edb/edgeql/parser/grammar/expressions.py
--- a/edb/edgeql/parser/grammar/expressions.py
+++ b/edb/edgeql/parser/grammar/expressions.py
@@ -264,6 +264,11 @@ def reduce_Insert(self, *kids):
         unless_conflict = kids[2].val
 
         if isinstance(subj, qlast.Shape):
+            if not subj.expr:
+                raise errors.EdgeQLSyntaxError(
+                    "insert shape expressions must have a type name",
+                    context=subj.context
+                )
             subj_path = subj.expr
             shape = subj.elements
         else:


Test patch:
diff --git a/tests/test_edgeql_syntax.py b/tests/test_edgeql_syntax.py
--- a/tests/test_edgeql_syntax.py
+++ b/tests/test_edgeql_syntax.py
@@ -3165,6 +3165,12 @@ def test_edgeql_syntax_insert_22(self):
         );
         """
 
+    @tb.must_fail(errors.EdgeQLSyntaxError)
+    def test_edgeql_syntex_insert_23(self):
+        """
+        INSERT { oops := "uhoh" };
+        """
+
     def test_edgeql_syntax_delete_01(self):
         """
         DELETE Foo;