Repository: edgedb/edgedb

Issue:
Invalid constraint definition error without indication of where the error is
This error doesn't give the user much help locating the error in their file. It would be nice to have a line number and column.

```bash
$ edgedb -I workout create-migration
ERROR: InvalidConstraintDefinitionError: constraints cannot contain paths with more than one hop
edgedb error: cannot proceed until .esdl files are fixed
```

schema.esdl
```
module default {
	type Exercise {
		required property name -> str {
			constraint exclusive;
		};
	}
	type Set_ {
		link workout := .<sets[IS Workout];
		required link exercise -> Exercise;
		required property index -> int16 {
			constraint min_value(0);
		};
		required property weight -> float32;
		required property reps -> int16;
		required property completed -> bool {
			default := false;
		};

		constraint exclusive on ( (.index, .workout) );
	}
	type Workout {
		multi link sets -> Set_ {
			constraint exclusive;
		}
		required property started_at -> datetime {
			constraint exclusive;
			default := datetime_current();
		}
	}
};
```
<!-- Please search existing issues to avoid creating duplicates. -->
- EdgeDB Version: package:1.0b2.dev5478+g25318fe0e-2021022200~focal.nightly
- EdgeDB CLI Version: edgedb-cli 1.0.0-beta.1
- OS Version: Linux 5.8.0-44-generic edgedb/edgedb-cli#50~20.04.1-Ubuntu SMP Wed Feb 10 21:07:30 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux


Discussion:
I believe this is server issue. Let me know if not.
I added this error message pretty recently and it is *supposed* to come with error context, so I'll take a look

Resolving patch:
diff --git a/edb/schema/constraints.py b/edb/schema/constraints.py
--- a/edb/schema/constraints.py
+++ b/edb/schema/constraints.py
@@ -885,11 +885,6 @@ def _populate_concrete_constraint_attrs(
 
         attrs['args'] = args
 
-        if expr.text == '__subject__':
-            expr_context = sourcectx
-        else:
-            expr_context = None
-
         assert subject is not None
         path_prefix_anchor = (
             qlast.Subject().name if isinstance(subject, s_types.Type)
@@ -915,7 +910,7 @@ def _populate_concrete_constraint_attrs(
                 f'{name} constraint expression expected '
                 f'to return a bool value, got '
                 f'{expr_type.get_verbosename(schema)}',
-                context=expr_context
+                context=sourcectx
             )
 
         if subjectexpr is not None:
@@ -951,7 +946,7 @@ def _populate_concrete_constraint_attrs(
                         raise errors.InvalidConstraintDefinitionError(
                             "constraints cannot contain paths with more "
                             "than one hop",
-                            context=ref.context,
+                            context=sourcectx
                         )
 
                     ref = rptr.source
@@ -960,7 +955,7 @@ def _populate_concrete_constraint_attrs(
                 raise errors.InvalidConstraintDefinitionError(
                     "cannot reference multiple links or properties in a "
                     "constraint where at least one link or property is MULTI",
-                    context=expr_context
+                    context=sourcectx
                 )
 
             if has_multi and ir_utils.contains_set_of_op(
@@ -968,7 +963,7 @@ def _populate_concrete_constraint_attrs(
                 raise errors.InvalidConstraintDefinitionError(
                     "cannot use aggregate functions or operators "
                     "in a non-aggregating constraint",
-                    context=expr_context
+                    context=sourcectx
                 )
 
         attrs['return_type'] = constr_base.get_return_type(schema)


Test patch: