Skip to content

parser: several E2002 errors pass hint text as the SQL source, printing a bogus context snippet #616

Closed

Description

@ajitpratap0

Summary

Several goerrors.ExpectedTokenError(...) calls in the parser pass a human-readable hint string as the sql argument. The error context then shows that sentence as "line 1" of the query, with the caret at the real column. #585 fixed this for qualifier errors only.

Reproduction

_, err := gosqlx.Parse("SELECT a FROM t WHERE ) ")
fmt.Println(err)

Observed on main 61ca6c8:

gosqlx: syntax error: Error E2002 at line 1, column 23: expected expression after WHERE, got RPAREN

   1 | WHERE clause requires a boolean expression
                                 ^^^^^^

Hint: expected expression after WHERE here

Expected: the context line shows the actual SQL (SELECT a FROM t WHERE ) ), and the explanatory sentence goes in the hint or message.

Notes

Call sites that pass a sentence as sql:

  • pkg/sql/parser/select_clauses.go:546 (WHERE)
  • pkg/sql/parser/select_clauses.go:520 (PREWHERE)
  • pkg/sql/parser/select_clauses.go:79 (FROM)
  • pkg/sql/parser/select_clauses.go:435, 447, 461, 476, 488 (SAMPLE)
  • pkg/sql/parser/select.go:385 (SELECT list)

Suggested direction: pass the parser's source SQL (or "" when it is not available), and move the sentence into .WithHint(...). A grep for ExpectedTokenError( with a capitalized sentence as the fourth argument finds these call sites.

Found during review of #597.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions