Skip to content

Commit

Permalink
sql: fix panic when getting support bundle
Browse files Browse the repository at this point in the history
Check for nil `plan.stmt` and AST when finishing the support bundle.

Fixes #56705.

Release note (bug fix): fixed internal error when collecting a
statement diagnostic bundle in some cases where the query hits an
error.
  • Loading branch information
RaduBerinde committed Nov 17, 2020
1 parent 06d1eb1 commit b013a62
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/sql/explain_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,16 @@ func (b *stmtBundleBuilder) addStatement() {
cfg.Simplify = true
cfg.Align = tree.PrettyNoAlign
cfg.JSONFmt = true
output := cfg.Pretty(b.plan.stmt.AST)
var output string
// If we hit an early error, stmt or stmt.AST might not be initialized yet.
switch {
case b.plan.stmt == nil:
output = "No Statement."
case b.plan.stmt.AST == nil:
output = "No AST."
default:
output = cfg.Pretty(b.plan.stmt.AST)
}

if b.placeholders != nil && len(b.placeholders.Values) != 0 {
var buf bytes.Buffer
Expand Down

0 comments on commit b013a62

Please sign in to comment.