Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: expose antlr runtime raw error message (#13671)

h3n4l3d5b9a3fc5dc
diff --git a/backend/api/lsp/fs_handler.go b/backend/api/lsp/fs_handler.go
index 7faf7d8168..af15f76d8a 100644
--- a/backend/api/lsp/fs_handler.go
+++ b/backend/api/lsp/fs_handler.go
@@ -171,7 +171,9 @@ func collectDiagnostics(err *base.SyntaxError) []lsp.Diagnostic {
},
Severity: lsp.Error,
Source: "Syntax check",
- Message: err.Message,
+ // Use RawMessage which created by antlr runtime, do not need our fine-tuned message
+ // because we had indicated the error position in the message.
+ Message: err.RawMessage,
}
return []lsp.Diagnostic{syntaxDiagnostic}
diff --git a/backend/plugin/parser/base/base.go b/backend/plugin/parser/base/base.go
index 6f1aec05f6..bc583b2662 100644
--- a/backend/plugin/parser/base/base.go
+++ b/backend/plugin/parser/base/base.go
@@ -39,9 +39,10 @@ type SingleSQL struct {
// SyntaxError is a syntax error.
type SyntaxError struct {
- Line int
- Column int
- Message string
+ Line int
+ Column int
+ Message string
+ RawMessage string
}
// Error returns the error message.
@@ -56,7 +57,7 @@ type ParseErrorListener struct {
}
// SyntaxError returns the errors.
-func (l *ParseErrorListener) SyntaxError(_ antlr.Recognizer, token any, line, column int, _ string, _ antlr.RecognitionException) {
+func (l *ParseErrorListener) SyntaxError(_ antlr.Recognizer, token any, line, column int, message string, _ antlr.RecognitionException) {
if l.Err == nil {
errMessage := ""
if token, ok := token.(*antlr.CommonToken); ok {
@@ -72,9 +73,10 @@ func (l *ParseErrorListener) SyntaxError(_ antlr.Recognizer, token any, line, co
errMessage = fmt.Sprintf("related text: %s", stream.GetTextFromInterval(antlr.NewInterval(start, stop)))
}
l.Err = &SyntaxError{
- Line: line + l.BaseLine,
- Column: column,
- Message: fmt.Sprintf("Syntax error at line %d:%d \n%s", line+l.BaseLine, column, errMessage),
+ Line: line + l.BaseLine,
+ Column: column,
+ Message: fmt.Sprintf("Syntax error at line %d:%d \n%s", line+l.BaseLine, column, errMessage),
+ RawMessage: message,
}
}
}