Skip to content

Commit 856779c

Browse files
fix(compiler): Prevent panic when compiler is nil (#2942)
Resolves #2939
1 parent f80cee1 commit 856779c

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

internal/cmd/generate.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,11 @@ func remoteGenerate(ctx context.Context, configPath string, conf *config.Config,
348348
func parse(ctx context.Context, name, dir string, sql config.SQL, combo config.CombinedSettings, parserOpts opts.Parser, stderr io.Writer) (*compiler.Result, bool) {
349349
defer trace.StartRegion(ctx, "parse").End()
350350
c, err := compiler.NewCompiler(sql, combo)
351-
defer c.Close(ctx)
351+
defer func() {
352+
if c != nil {
353+
c.Close(ctx)
354+
}
355+
}()
352356
if err != nil {
353357
fmt.Fprintf(stderr, "error creating compiler: %s\n", err)
354358
return nil, true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- name: Test :exec
2+
SELECT 1;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
sql:
3+
- queries: query.sql
4+
schema: query.sql
5+
engine: "bad_engine"
6+
gen:
7+
go:
8+
out: "db"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
error creating compiler: unknown engine: bad_engine

0 commit comments

Comments
 (0)