Skip to content

Commit

Permalink
fix(compiler): Prevent panic when compiler is nil (#2942)
Browse files Browse the repository at this point in the history
Resolves #2939
  • Loading branch information
andrewmbenton authored Nov 3, 2023
1 parent f80cee1 commit 856779c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@ func remoteGenerate(ctx context.Context, configPath string, conf *config.Config,
func parse(ctx context.Context, name, dir string, sql config.SQL, combo config.CombinedSettings, parserOpts opts.Parser, stderr io.Writer) (*compiler.Result, bool) {
defer trace.StartRegion(ctx, "parse").End()
c, err := compiler.NewCompiler(sql, combo)
defer c.Close(ctx)
defer func() {
if c != nil {
c.Close(ctx)
}
}()
if err != nil {
fmt.Fprintf(stderr, "error creating compiler: %s\n", err)
return nil, true
Expand Down
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/bad_config/engine/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- name: Test :exec
SELECT 1;
8 changes: 8 additions & 0 deletions internal/endtoend/testdata/bad_config/engine/sqlc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
sql:
- queries: query.sql
schema: query.sql
engine: "bad_engine"
gen:
go:
out: "db"
1 change: 1 addition & 0 deletions internal/endtoend/testdata/bad_config/engine/stderr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error creating compiler: unknown engine: bad_engine

0 comments on commit 856779c

Please sign in to comment.