Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more context to schema parse errors #408

Merged
merged 1 commit into from
Feb 8, 2022

Conversation

josephschorr
Copy link
Member

No description provided.

@josephschorr josephschorr requested a review from ecordell February 7, 2022 18:35
@github-actions github-actions bot added area/api v0 Affects the v0 API area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Feb 7, 2022
@@ -98,11 +98,12 @@ func TestEditCheck(t *testing.T) {
[]*v0.RelationTuple{},
[]*v0.RelationTuple{},
&v0.DeveloperError{
Message: "parse error in `schema`, line 3, column 4: Expected identifier, found token TokenTypeRightBrace",
Message: "Expected identifier, found token TokenTypeRightBrace",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this message be more readable with } instead of TokenTypeRightBrace?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually what I'm passing along now out of band from the error message itself. We could change the error message as well, but it would require a reverse map of the token types (which, I suppose would be fairly easy to do), but may appear odd for non-ASCII runes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a follow up, but it would it make sense to not keep a reverse map, but instead keep an "error message map"? then we can write the best representation for any given token.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we could do that too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do that as a followup

error: fmt.Errorf("parse error in %s: %s", formattedRange, errMessage),
SourceRange: sourceRange,
Source: input.Source(source),
error: fmt.Errorf("parse error in %s: %s", formattedRange, errMessage),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the thing you're doing here with error/BaseErrorMessage basically what you get with golang's error wrapping?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I wanted it to be explicit from the compiler's error type

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But whenever you wanted to get the underlying error, you can just errors.As(err, &BaseError{}) to get it back out. I'm not clear on the advantage to doing it outside the stdlib?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we'd have to declare another error type to do that. Do you prefer that approach?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be more flexible, right? Then we could layer in other error types in the hierarchy if we needed

If you think it's more effort than it's worth this lgtm otherwise

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@josephschorr josephschorr force-pushed the better-schema-parse-errors branch from 0382172 to dbc4f6c Compare February 8, 2022 16:54
Copy link
Contributor

@ecordell ecordell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@josephschorr josephschorr merged commit b0f9678 into authzed:main Feb 8, 2022
@josephschorr josephschorr deleted the better-schema-parse-errors branch February 8, 2022 17:33
@github-actions github-actions bot locked and limited conversation to collaborators Feb 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/api v0 Affects the v0 API area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants