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

Function convertParseError

backend/plugin/parser/doris/doris.go:122–140  ·  view source on GitHub ↗

convertParseError converts an omni *parser.ParseError to a *base.SyntaxError that sql_service.go recognises for structured error diagnostics. It converts the byte offset in ParseError.Loc to 1-based line and 1-based column (rune-based) matching the storepb.Position convention used across other omni

(statement string, pe *parser.ParseError, basePos *storepb.Position)

Source from the content-addressed store, hash-verified

120// errors from parsing an isolated statement segment are reported in the
121// coordinates of the original multi-statement script.
122func convertParseError(statement string, pe *parser.ParseError, basePos *storepb.Position) *base.SyntaxError {
123 line, col := byteOffsetToPosition(statement, pe.Loc.Start)
124 if basePos != nil {
125 // The first line of the segment shares a line with basePos, so
126 // column offsets only apply when the error is on that line.
127 if line == 1 {
128 col = int(basePos.Column) + col - 1
129 }
130 line = int(basePos.Line) + line - 1
131 }
132 return &base.SyntaxError{
133 Position: &storepb.Position{
134 Line: int32(line),
135 Column: int32(col),
136 },
137 Message: pe.Error(),
138 RawMessage: pe.Msg,
139 }
140}
141
142// byteOffsetToPosition converts a 0-based byte offset to a 1-based line and
143// 1-based column (in runes).

Callers 2

parseDorisStatementsFunction · 0.70
parseDorisSQLFunction · 0.70

Calls 2

byteOffsetToPositionFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected