File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
internal/engine/postgresql Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -10,9 +10,11 @@ import (
1010 "strings"
1111
1212 nodes "github.com/pganalyze/pg_query_go/v4"
13+ "github.com/pganalyze/pg_query_go/v4/parser"
1314
1415 "github.com/kyleconroy/sqlc/internal/metadata"
1516 "github.com/kyleconroy/sqlc/internal/sql/ast"
17+ "github.com/kyleconroy/sqlc/internal/sql/sqlerr"
1618)
1719
1820func stringSlice (list * nodes.List ) []string {
@@ -158,7 +160,8 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
158160 }
159161 tree , err := nodes .Parse (string (contents ))
160162 if err != nil {
161- return nil , err
163+ pErr := normalizeErr (err )
164+ return nil , pErr
162165 }
163166
164167 var stmts []ast.Statement
@@ -184,6 +187,20 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
184187 return stmts , nil
185188}
186189
190+ func normalizeErr (err error ) error {
191+ pErr := parser.Error {}
192+ if errors .As (err , & pErr ) {
193+ sErr := & sqlerr.Error {
194+ Message : pErr .Message ,
195+ Err : & pErr ,
196+ Line : pErr .Lineno ,
197+ Location : pErr .Cursorpos ,
198+ }
199+ return sErr
200+ }
201+ return err
202+ }
203+
187204// https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-COMMENTS
188205func (p * Parser ) CommentSyntax () metadata.CommentSyntax {
189206 return metadata.CommentSyntax {
You can’t perform that action at this time.
0 commit comments