Skip to content

Commit e53499d

Browse files
committed
Release 1.17.11
- Prevent divide-by-zero error while loading csv files. ([GitHub #89](#89)) - Handle panics during processor executions.
2 parents 37d3db3 + 6550a9b commit e53499d

16 files changed

+218
-56
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## Version 1.17.11
4+
5+
Released on Nov 5, 2022
6+
7+
- Prevent divide-by-zero error while loading csv files. ([GitHub #89](https://github.com/mithrandie/csvq/issues/89))
8+
- Handle panics during processor executions.
9+
310
## Version 1.17.10
411

512
Released on Aug 14, 2022

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ This tool may be useful for those who want to handle data easily and roughly, wi
4242
* Transaction Management
4343
* Support loading data from Standard Input
4444
* Support following file formats
45-
* CSV
45+
* [CSV](https://datatracker.ietf.org/doc/html/rfc4180)
4646
* TSV
47-
* LTSV
47+
* [LTSV](http://ltsv.org)
4848
* Fixed-Length Format
49-
* JSON
50-
* JSON Lines
49+
* [JSON](https://datatracker.ietf.org/doc/html/rfc8259)
50+
* [JSON Lines](https://jsonlines.org)
5151
* Support following file encodings
5252
* UTF-8
5353
* UTF-16

docs/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ title: Change Log - csvq
55

66
# Change Log
77

8+
## Version 1.17.11
9+
10+
Released on Nov 5, 2022
11+
12+
- Prevent divide-by-zero error while loading csv files. ([GitHub #89](https://github.com/mithrandie/csvq/issues/89))
13+
- Handle panics during processor executions.
14+
815
## Version 1.17.10
916

1017
Released on Aug 14, 2022

docs/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ In the multiple operations, you can use variables, cursors, temporary tables, an
1313

1414
## Latest Release
1515

16-
Version 1.17.10
17-
: Released on Aug 14, 2022
16+
Version 1.17.11
17+
: Released on Nov 5, 2022
1818

19-
<a class="waves-effect waves-light btn" href="https://github.com/mithrandie/csvq/releases/tag/v1.17.10">
19+
<a class="waves-effect waves-light btn" href="https://github.com/mithrandie/csvq/releases/tag/v1.17.11">
2020
<i class="material-icons left">file_download</i>download
2121
</a>
2222

@@ -46,12 +46,12 @@ This tool may be useful for those who want to handle data easily and roughly, wi
4646
* [Transaction Management]({{ '/reference/transaction.html' | relative_url }})
4747
* Support loading data from Standard Input
4848
* Support following file formats
49-
* CSV
49+
* [CSV](https://datatracker.ietf.org/doc/html/rfc4180)
5050
* TSV
51-
* LTSV
51+
* [LTSV](http://ltsv.org)
5252
* Fixed-Length Format
53-
* [JSON]({{ '/reference/json.html' | relative_url }})
54-
* JSON Lines
53+
* [JSON](https://datatracker.ietf.org/doc/html/rfc8259)
54+
* [JSON Lines](https://jsonlines.org)
5555
* Support following file encodings
5656
* UTF-8
5757
* UTF-16

docs/sitemap.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
77
<url>
88
<loc>https://mithrandie.github.io/csvq/</loc>
9-
<lastmod>2022-08-14T07:45:53+00:00</lastmod>
9+
<lastmod>2022-11-05T14:32:12+00:00</lastmod>
1010
</url>
1111
<url>
1212
<loc>https://mithrandie.github.io/csvq/reference.html</loc>
@@ -182,7 +182,7 @@
182182
</url>
183183
<url>
184184
<loc>https://mithrandie.github.io/csvq/changelog.html</loc>
185-
<lastmod>2022-08-14T07:45:53+00:00</lastmod>
185+
<lastmod>2022-11-05T14:32:12+00:00</lastmod>
186186
</url>
187187
<url>
188188
<loc>https://mithrandie.github.io/csvq/license.html</loc>

lib/cli/help.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cli
33
var appHHelpTemplate = `Name:
44
{{.Name}}{{if .Usage}} - {{.Usage}}{{end}}
55
6-
https://mithrandie.github.io/csvq
6+
https://mithrandie.github.io/csvq/
77
88
Usage:
99
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[options]{{end}}{{if .Commands}} [subcommand]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}

lib/query/analytic_function.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ func Analyze(ctx context.Context, scope *ReferenceScope, view *View, fn parser.A
130130
gm := NewGoroutineTaskManager(len(partitionMapKeys), minReq, scope.Tx.Flags.CPU)
131131

132132
var analyzeFn = func(thIdx int) {
133+
defer func() {
134+
if !gm.HasError() {
135+
if panicReport := recover(); panicReport != nil {
136+
gm.SetError(NewFatalError(panicReport))
137+
}
138+
}
139+
140+
if 1 < gm.Number {
141+
gm.Done()
142+
}
143+
}()
144+
133145
start, end := gm.RecordRange(thIdx)
134146
seqScope := scope.CreateScopeForSequentialEvaluation(view)
135147

@@ -197,10 +209,6 @@ func Analyze(ctx context.Context, scope *ReferenceScope, view *View, fn parser.A
197209
}
198210
}
199211
}
200-
201-
if 1 < gm.Number {
202-
gm.Done()
203-
}
204212
}
205213

206214
if 1 < gm.Number {

lib/query/error.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"reflect"
8+
"runtime"
89
"strconv"
910
"strings"
1011

@@ -266,6 +267,34 @@ func NewBaseErrorWithPrefix(prefix string, message string, code int, number int)
266267
}
267268
}
268269

270+
type FatalError struct {
271+
*BaseError
272+
}
273+
274+
func NewFatalError(panicReport interface{}) error {
275+
stacks := make([]string, 0, 30)
276+
for depth := 0; ; depth++ {
277+
pc, src, line, ok := runtime.Caller(depth)
278+
if !ok {
279+
break
280+
}
281+
if depth == 0 {
282+
continue
283+
}
284+
stacks = append(stacks, fmt.Sprintf(" %d: %s [%s:%d]", depth-1, runtime.FuncForPC(pc).Name(), src, line))
285+
}
286+
287+
message := fmt.Sprintf("%v\n", panicReport) +
288+
"An unexpected error has occurred. Please report this problem to: https://github.com/mithrandie/csvq/issues\n" +
289+
"\n" +
290+
"Stack:\n" +
291+
strings.Join(stacks, "\n")
292+
293+
return &FatalError{
294+
NewBaseErrorWithPrefix("Fatal Error", message, ReturnCodeApplicationError, ErrorFatal),
295+
}
296+
}
297+
269298
type SystemError struct {
270299
*BaseError
271300
}

lib/query/error_code.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const (
1515

1616
const (
1717
//Application Error
18+
ErrorFatal = 1
1819
ErrorCannotDetectFileEncoding = 10001
1920
ErrorFieldAmbiguous = 10101
2021
ErrorFieldNotExist = 10102

lib/query/eval.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ func Evaluate(ctx context.Context, scope *ReferenceScope, expr parser.QueryExpre
102102
}
103103

104104
func evaluateSequentialRoutine(ctx context.Context, scope *ReferenceScope, view *View, fn func(*ReferenceScope, int) error, thIdx int, gm *GoroutineTaskManager) {
105+
defer func() {
106+
if !gm.HasError() {
107+
if panicReport := recover(); panicReport != nil {
108+
gm.SetError(NewFatalError(panicReport))
109+
}
110+
}
111+
112+
if 1 < gm.Number {
113+
gm.Done()
114+
}
115+
}()
116+
105117
start, end := gm.RecordRange(thIdx)
106118
seqScope := scope.CreateScopeForSequentialEvaluation(
107119
&View{
@@ -127,10 +139,6 @@ func evaluateSequentialRoutine(ctx context.Context, scope *ReferenceScope, view
127139

128140
i++
129141
}
130-
131-
if 1 < gm.Number {
132-
gm.Done()
133-
}
134142
}
135143

136144
func EvaluateSequentially(ctx context.Context, scope *ReferenceScope, view *View, fn func(*ReferenceScope, int) error) error {

0 commit comments

Comments
 (0)