MCPcopy Create free account
hub / github.com/bytebase/bytebase / convertOmniError

Function convertOmniError

backend/plugin/parser/pg/pg.go:53–72  ·  view source on GitHub ↗

convertOmniError converts an omni parser error to a base.SyntaxError with proper line:column position.

(err error, _ string, stmt base.Statement)

Source from the content-addressed store, hash-verified

51
52// convertOmniError converts an omni parser error to a base.SyntaxError with proper line:column position.
53func convertOmniError(err error, _ string, stmt base.Statement) error {
54 var parseErr *omniparser.ParseError
55 if !errors.As(err, &parseErr) {
56 return err
57 }
58
59 // Convert byte offset within stmt.Text to line:column.
60 pos := ByteOffsetToRunePosition(stmt.Text, parseErr.Position)
61
62 // Adjust line by the statement's base line (stmt.Start.Line is 1-based).
63 if stmt.Start != nil {
64 pos.Line += stmt.Start.Line - 1
65 }
66
67 return &base.SyntaxError{
68 Position: pos,
69 Message: fmt.Sprintf("Syntax error at line %d: %s", pos.Line, parseErr.Message),
70 RawMessage: parseErr.Message,
71 }
72}
73
74// normalizePostgreSQLQuotedIdentifier removes surrounding double quotes and unescapes internal ones.
75func normalizePostgreSQLQuotedIdentifier(s string) string {

Callers 1

parsePgStatementsFunction · 0.70

Calls 1

ByteOffsetToRunePositionFunction · 0.70

Tested by

no test coverage detected