Skip to content

sql/parser: better error messages for unimplemented features#42347

Open
andreimatei wants to merge 1 commit intocockroachdb:masterfrom
andreimatei:sql.unimplemented-errors
Open

sql/parser: better error messages for unimplemented features#42347
andreimatei wants to merge 1 commit intocockroachdb:masterfrom
andreimatei:sql.unimplemented-errors

Conversation

@andreimatei
Copy link
Copy Markdown
Contributor

Before this patch, error messages for unimplemented features detected by
the parser looked like:
reate type t as enum('a');
invalid syntax: statement ignored: at or near "a": syntax error: unimplemented: this syntax

after this patch, they spell out the missing feature:
invalid syntax: statement ignored: at or near "a": syntax error: unimplemented: enum types

The information about the feature is already present when creating the
error and was used as a "detail" for telemetry. Now I've made it part of
the error message too.

Release note (sql change): Error messages for unimplemented features
have been improved to spell out what the unimplemented feature is.

@andreimatei andreimatei requested a review from knz November 10, 2019 18:40
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@andreimatei
Copy link
Copy Markdown
Contributor Author

I'm not sure this is the right way to go because I don't really understand what that "detail" that I've reused was. PTAL.

@awoods187
Copy link
Copy Markdown

This is cool! I love improving the error messages here.

Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

LGTM on the approach but there are two things that you need to take into account:

  1. you'll need to fix the newly failing test. I think the way to do this is not just by changing the expected string, and instead by changing the provided detail. The text "unimplemented feature: *IndirectionExpr" is obscure and useless, it would be better for the user to see "unimplemented feature: computed indexes" (sql.go line 5216, linking to issue #9682).

  2. while fixing point 1, be careful about not changing the detail argument to the unimplemented error, as this is the exact string that goes to telemetry. In telemetry (as opposed to the user's eyes) we do want to see *IndirectionExpr for the error linked to issue #9682. This is because a user attempting to use computed indexes may do so using various scalar expressions, and we want to find out int telemetry what are the expression types that are most commonly used.

In order to improve the user-facing detail while keeping the telemetry detail, you may need to introduce a variant of the unimplementedWithIssueDetail function that takes an extra argument.

Reviewed 3 of 3 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained

@bobvawter
Copy link
Copy Markdown
Contributor

bobvawter commented Mar 10, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

You really sure we want BinaryExpr and IndirectionExpr in telemetry for the computed indexes? It gets to be a bit unwieldy to add support for a telemetry key different from the error message. I can't imagine much utility for it either; the type of the node at the top of the expression AST hardly characterizes the expression, and I imagine that if we add support for computed indexes, we'll support all sorts of expressions from the get go anyway.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained

@andreimatei andreimatei force-pushed the sql.unimplemented-errors branch from 722c8f7 to 54558dc Compare May 10, 2020 03:47
Copy link
Copy Markdown
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

I've done the thing to keep the message different from the telemetry key for the computed indexes, but I'd personally rather get rid of it.
I've also changed purposelyUnimplemented() to pass the details as the message.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)

@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented May 10, 2020

❌ The GitHub CI (Cockroach) build has failed on 54558dcb.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

Copy link
Copy Markdown
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

friendly ping for when you're back Rafa

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)

@andreimatei andreimatei force-pushed the sql.unimplemented-errors branch from 54558dc to 974cd74 Compare July 6, 2020 15:25
Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained

@andreimatei andreimatei force-pushed the sql.unimplemented-errors branch from 974cd74 to bdf7575 Compare July 9, 2020 21:47
Before this patch, error messages for unimplemented features detected by
the parser looked like:
reate type t as enum('a');
invalid syntax: statement ignored: at or near "a": syntax error: unimplemented: this syntax

after this patch, they spell out the missing feature:
invalid syntax: statement ignored: at or near "a": syntax error: unimplemented: enum types

The information about the feature is already present when creating the
error and was used as a "detail" for telemetry. Now I've made it part of
the error message too.

Release note (sql change): Error messages for unimplemented features
have been improved to spell out what the unimplemented feature is.
@andreimatei andreimatei force-pushed the sql.unimplemented-errors branch from bdf7575 to b3db2c4 Compare July 9, 2020 22:18
Copy link
Copy Markdown
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

Rafa please help me out. The linter says

    TestLint/TestRoachVet: lint_test.go:85:
        pkg/sql/parser/lexer.go:153:25: Unimplemented(): message argument is not a constant expression
        Tip: use YourFuncf("descriptive prefix %s", ...) or list new formatting wrappers in pkg/testutils/lint/passes/fmtsafe/functions.go.
        pkg/sql/parser/lexer.go:165:40: UnimplementedWithIssueDetail(): message argument is not a constant expression
        Tip: use YourFuncf("descriptive prefix %s", ...) or list new formatting wrappers in pkg/testutils/lint/passes/fmtsafe/functions.go.

This is about the lexer.Unimplemented() and lexer.UnimplementedWithIssueDetail() functions. I've tried a couple of things but I don't know how to shut it up. I can't use /* nolint:fmtsafe */ cause it's not test code. I tried adding these functions to the requireConstMsg list, but that doesn't seem to do the trick. The only thing that does the trick seems to be:

// UnimplementedWithIssueDetail wraps Error, setting lastUnimplementedError.
func (l *lexer) UnimplementedWithIssueDetail(issue int, detail string) {
	l.lastError = unimp.NewWithIssueDetailf(issue, detail /* detail */, "%s", detail)
	l.populateErrorDetails()
}

Is that what I was supposed to do?

Would it be reasonable to say that the body of the functions listed in requireConstMsg shouldn't be checked?

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)

@tbg tbg added the X-noremind Bots won't notify about PRs with X-noremind label May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

X-noremind Bots won't notify about PRs with X-noremind

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants