Skip to content

Commit 5494b36

Browse files
Luis Silvaluisfvieirasilva
Luis Silva
authored andcommitted
fix(lib/output): check if channels aren't nil before printing
1 parent d9b1ea6 commit 5494b36

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Diff for: src/lib/errors.go

+12
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,15 @@ type TransactionNotSupportedError struct{}
55
func (e *TransactionNotSupportedError) Error() string {
66
return "transactions are only supported in the shell using semicolons to separate each statement.\nFor example: \"BEGIN; [your SQL statements]; END\""
77
}
8+
9+
type InvalidStatementsResult struct{}
10+
11+
func (e *InvalidStatementsResult) Error() string {
12+
return "invalid statements result"
13+
}
14+
15+
type UnableToPrintStatementResult struct{}
16+
17+
func (e *UnableToPrintStatementResult) Error() string {
18+
return "unable to print statement result. You should check if its an error before printing it"
19+
}

Diff for: src/lib/output.go

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import (
1313
)
1414

1515
func PrintStatementsResult(statementsResult statementsResult, outF io.Writer, withoutHeader bool) error {
16+
if statementsResult.StatementResultCh == nil {
17+
return &InvalidStatementsResult{}
18+
}
19+
1620
for statementResult := range statementsResult.StatementResultCh {
1721
if statementResult.Err != nil {
1822
return statementResult.Err
@@ -27,6 +31,10 @@ func PrintStatementsResult(statementsResult statementsResult, outF io.Writer, wi
2731
}
2832

2933
func PrintStatementResult(statementResult statementResult, outF io.Writer, withoutHeader bool) error {
34+
if statementResult.RowCh == nil {
35+
return &UnableToPrintStatementResult{}
36+
}
37+
3038
if len(statementResult.ColumnNames) == 0 {
3139
return nil
3240
}

0 commit comments

Comments
 (0)