Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime/ztests/expr/function/parse-sup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ output: |
{a:1}
null
error({message:"parse_sup: string arg required",on:{}})
error({message:"parse_sup: SUP syntax error",on:"!"})
error({message:"parse_sup: line 1: parse error: syntax error",on:"!"})
2 changes: 1 addition & 1 deletion service/ztests/curl-load-error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ inputs:
outputs:
- name: stdout
data: |
{"type":"Error","kind":"invalid operation","error":"format detection error\n\tarrows: schema message length exceeds 1 MiB\n\tbsup: malformed BSUP value\n\tcsup: auto-detection requires seekable input\n\tcsv: line 1: EOF\n\tjson: invalid character 'T' looking for beginning of value\n\tline: auto-detection not supported\n\tparquet: auto-detection requires seekable input\n\tsup: SUP syntax error\n\ttsv: line 1: EOF\n\tzeek: line 1: bad types/fields definition in zeek header\n\tjsup: line 1: malformed JSUP: bad type object: \"This is not a detectable format.\": unpacker error parsing JSON: invalid character 'T' looking for beginning of value"}
{"type":"Error","kind":"invalid operation","error":"format detection error\n\tarrows: schema message length exceeds 1 MiB\n\tbsup: malformed BSUP value\n\tcsup: auto-detection requires seekable input\n\tcsv: line 1: EOF\n\tjson: invalid character 'T' looking for beginning of value\n\tline: auto-detection not supported\n\tparquet: auto-detection requires seekable input\n\tsup: line 1: parse error: syntax error\n\ttsv: line 1: EOF\n\tzeek: line 1: bad types/fields definition in zeek header\n\tjsup: line 1: malformed JSUP: bad type object: \"This is not a detectable format.\": unpacker error parsing JSON: invalid character 'T' looking for beginning of value"}
code 400
{"type":"Error","kind":"invalid operation","error":"unsupported MIME type: unsupported"}
code 400
2 changes: 1 addition & 1 deletion service/ztests/load-garbage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ outputs:
json: invalid character 'T' looking for beginning of value
line: auto-detection not supported
parquet: auto-detection requires seekable input
sup: SUP syntax error
sup: line 1: parse error: syntax error
tsv: line 1: delimiter '\t' not found
zeek: line 1: bad types/fields definition in zeek header
jsup: line 1: malformed JSUP: bad type object: "This file contains no records.": unpacker error parsing JSON: invalid character 'T' looking for beginning of value
Expand Down
6 changes: 6 additions & 0 deletions sup/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Lexer struct {
primitive *regexp.Regexp
indentation *regexp.Regexp
ip6follow *regexp.Regexp
line int
}

const (
Expand All @@ -43,6 +44,7 @@ func NewLexer(r io.Reader) *Lexer {
primitive: primitive,
indentation: indentation,
ip6follow: regexp.MustCompile(ip6followRE),
line: 1,
}
}

Expand Down Expand Up @@ -90,6 +92,7 @@ func (l *Lexer) skip(n int) error {
if err := l.check(n); err != nil {
return err
}
l.line += bytes.Count(l.cursor[:n], []byte{'\n'})
l.cursor = l.cursor[n:]
return nil
}
Expand Down Expand Up @@ -170,6 +173,9 @@ func (l *Lexer) readByte() (byte, error) {
}
b := l.cursor[0]
l.cursor = l.cursor[1:]
if b == '\n' {
l.line++
}
return b, nil
}

Expand Down
3 changes: 1 addition & 2 deletions sup/parser-values.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sup

import (
"encoding/hex"
"errors"
"fmt"
"io"
"net/netip"
Expand All @@ -22,7 +21,7 @@ func (p *Parser) ParseValue() (ast.Value, error) {
}
if v == nil && err == nil {
if err := p.lexer.check(1); (err != nil && err != io.EOF) || len(p.lexer.cursor) > 0 {
return nil, errors.New("SUP syntax error")
return nil, p.error("syntax error")
}
}
return v, err
Expand Down
4 changes: 1 addition & 3 deletions sup/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ func (p *Parser) errorf(msg string, args ...any) error {
}

func (p *Parser) error(msg string) error {
// format a message based on the contents in the scanner buffer
// (could also track column and line number)
return fmt.Errorf("parse error: %s", msg)
return fmt.Errorf("line %d: parse error: %s", p.lexer.line, msg)
}
36 changes: 36 additions & 0 deletions sup/ztests/parser-errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Test parse errors with unescaped quotes.
spq: pass

input: |
{id:1,text:"valid record before the bad one"}
{id:2,text:"this has "unescaped quotes" inside it"}
{id:3,text:"valid record after the bad one"}

error: |
line 2: parse error: mismatched braces while parsing record type

---

# Unclosed object.
spq: pass

input: |
{x:1}
{x:2}
{x:3
{x:4}

error: |
line 4: parse error: mismatched braces while parsing record type

---

spq: pass

input-flags: -i sup

input: |
{x}

error: |
line 1: parse error: no type name found for field "x"
Loading