mirror of
https://github.com/wader/fq.git
synced 2024-08-16 23:40:43 +03:00
Merge pull request #929 from wader/decode-iopanic-cleanup
decode: Cleanup io panic a bit
This commit is contained in:
commit
efa847faf1
@ -281,7 +281,7 @@ func decodeASN1BERValue(d *decode.D, bib *bitio.Buffer, sb *strings.Builder, par
|
||||
if bib != nil {
|
||||
// TODO: helper?
|
||||
if _, err := bitio.Copy(bib, br); err != nil {
|
||||
d.IOPanic(err, "bitio.Copy")
|
||||
d.IOPanic(err, "value", "bitio.Copy")
|
||||
}
|
||||
}
|
||||
if unusedBitsCount > 0 {
|
||||
@ -292,7 +292,7 @@ func decodeASN1BERValue(d *decode.D, bib *bitio.Buffer, sb *strings.Builder, par
|
||||
if bib != nil {
|
||||
// TODO: helper?
|
||||
if _, err := bitio.Copy(bib, br); err != nil {
|
||||
d.IOPanic(err, "bitio.Copy")
|
||||
d.IOPanic(err, "value", "bitio.Copy")
|
||||
}
|
||||
}
|
||||
case class == classUniversal && tag == universalTypeNull:
|
||||
|
@ -114,7 +114,7 @@ func gzipDecodeMember(d *decode.D) bitio.ReaderAtSeeker {
|
||||
readCompressedSize, uncompressedBR, err =
|
||||
d.FieldReaderRange("uncompressed", d.Pos(), d.BitsLeft(), rFn)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "TryFieldReaderRange")
|
||||
d.IOPanic(err, "uncompressed", "FieldReaderRange")
|
||||
}
|
||||
d.FieldRawLen("compressed", readCompressedSize)
|
||||
crc32W := crc32.NewIEEE()
|
||||
@ -149,7 +149,7 @@ func gzipDecode(d *decode.D) any {
|
||||
|
||||
cbr, err := bitio.NewMultiReader(brs...)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "NewMultiReader")
|
||||
d.IOPanic(err, "members", "NewMultiReader")
|
||||
}
|
||||
dv, _, _ := d.TryFieldFormatBitBuf("uncompressed", cbr, &probeGroup, format.Probe_In{})
|
||||
if dv == nil {
|
||||
|
@ -302,7 +302,7 @@ func textNullLenFn(encoding int, notFoundFixedBytes int) func(d *decode.D) strin
|
||||
func(v uint64) bool { return v == 0 },
|
||||
)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "textNullLenFn")
|
||||
d.IOPanic(err, "", "textNullLenFn")
|
||||
}
|
||||
if offset < 0 {
|
||||
if notFoundFixedBytes < 0 {
|
||||
|
@ -263,7 +263,7 @@ func (d *D) TryCopyBits(w io.Writer, r bitio.Reader) (int64, error) {
|
||||
func (d *D) CopyBits(w io.Writer, r bitio.Reader) int64 {
|
||||
n, err := d.TryCopyBits(w, r)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "CopyBits: Copy")
|
||||
d.IOPanic(err, "", "CopyBits")
|
||||
}
|
||||
return n
|
||||
}
|
||||
@ -277,7 +277,7 @@ func (d *D) TryCopy(w io.Writer, r io.Reader) (int64, error) {
|
||||
func (d *D) Copy(w io.Writer, r io.Reader) int64 {
|
||||
n, err := d.TryCopy(w, r)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "Copy")
|
||||
d.IOPanic(err, "", "Copy")
|
||||
}
|
||||
return n
|
||||
}
|
||||
@ -285,7 +285,7 @@ func (d *D) Copy(w io.Writer, r io.Reader) int64 {
|
||||
func (d *D) CloneReadSeeker(br bitio.ReadSeeker) bitio.ReadSeeker {
|
||||
br, err := bitio.CloneReadSeeker(br)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "CloneReadSeeker")
|
||||
d.IOPanic(err, "", "CloneReadSeeker")
|
||||
}
|
||||
return br
|
||||
}
|
||||
@ -308,7 +308,7 @@ func (d *D) TryReadAllBits(r bitio.Reader) ([]byte, error) {
|
||||
func (d *D) ReadAllBits(r bitio.Reader) []byte {
|
||||
buf, err := d.TryReadAllBits(r)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "Bytes ReadAllBytes")
|
||||
d.IOPanic(err, "", "ReadAllBytes")
|
||||
}
|
||||
return buf
|
||||
}
|
||||
@ -350,7 +350,7 @@ func (d *D) FillGaps(r ranges.Range, namePrefix string) {
|
||||
for i, gap := range gaps {
|
||||
br, err := bitiox.Range(d.bitBuf, gap.Start, gap.Len)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "FillGaps: Range")
|
||||
d.IOPanic(err, namePrefix, "bitiox.Range")
|
||||
}
|
||||
|
||||
v := &Value{
|
||||
@ -380,8 +380,8 @@ func (d *D) Fatalf(format string, a ...any) {
|
||||
panic(DecoderError{Reason: fmt.Sprintf(format, a...), Pos: d.Pos()})
|
||||
}
|
||||
|
||||
func (d *D) IOPanic(err error, op string) {
|
||||
panic(IOError{Err: err, Pos: d.Pos(), Op: op})
|
||||
func (d *D) IOPanic(err error, name string, op string) {
|
||||
panic(IOError{Err: err, Name: name, Pos: d.Pos(), Op: op})
|
||||
}
|
||||
|
||||
// TryBits reads nBits bits from buffer
|
||||
@ -543,7 +543,7 @@ func (d *D) TryPeekFind(nBits int, seekBits int64, maxLen int64, fn func(v uint6
|
||||
func (d *D) PeekFind(nBits int, seekBits int64, maxLen int64, fn func(v uint64) bool) (int64, uint64) {
|
||||
peekBits, v, err := d.TryPeekFind(nBits, seekBits, maxLen, fn)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "PeekFind: TryPeekFind")
|
||||
d.IOPanic(err, "", "PeekFind")
|
||||
}
|
||||
if peekBits == -1 {
|
||||
d.Errorf("peek not found")
|
||||
@ -771,7 +771,7 @@ func (d *D) TrySeekRel(delta int64, fns ...func(d *D)) (int64, error) {
|
||||
func (d *D) SeekRel(delta int64, fns ...func(d *D)) int64 {
|
||||
n, err := d.trySeekAbs(d.Pos()+delta, fns...)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "SeekRel")
|
||||
d.IOPanic(err, "", "SeekRel")
|
||||
}
|
||||
return n
|
||||
}
|
||||
@ -785,7 +785,7 @@ func (d *D) TrySeekAbs(pos int64, fns ...func(d *D)) (int64, error) {
|
||||
func (d *D) SeekAbs(pos int64, fns ...func(d *D)) int64 {
|
||||
n, err := d.trySeekAbs(pos, fns...)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "SeekAbs")
|
||||
d.IOPanic(err, "", "SeekAbs")
|
||||
}
|
||||
return n
|
||||
}
|
||||
@ -955,7 +955,7 @@ func (d *D) RangeFn(firstBit int64, nBits int64, fn func(d *D)) int64 {
|
||||
// TODO: do some kind of DecodeLimitedLen/RangeFn?
|
||||
br := d.BitBufRange(0, firstBit+nBits)
|
||||
if _, err := br.SeekBits(firstBit, io.SeekStart); err != nil {
|
||||
d.IOPanic(err, "RangeFn: SeekAbs")
|
||||
d.IOPanic(err, "", "RangeFn: SeekAbs")
|
||||
}
|
||||
|
||||
nd := *d
|
||||
@ -979,7 +979,7 @@ func (d *D) Format(group *Group, inArg any) any {
|
||||
ReadBuf: d.readBuf,
|
||||
})
|
||||
if dv == nil || dv.Errors() != nil {
|
||||
d.IOPanic(err, "Format: decode")
|
||||
d.IOPanic(err, "", "Format: decode")
|
||||
}
|
||||
|
||||
switch vv := dv.V.(type) {
|
||||
@ -992,7 +992,7 @@ func (d *D) Format(group *Group, inArg any) any {
|
||||
}
|
||||
|
||||
if _, err := d.bitBuf.SeekBits(dv.Range.Len, io.SeekCurrent); err != nil {
|
||||
d.IOPanic(err, "Format: SeekRel")
|
||||
d.IOPanic(err, "", "Format: SeekRel")
|
||||
}
|
||||
|
||||
return v
|
||||
@ -1015,7 +1015,7 @@ func (d *D) TryFieldFormat(name string, group *Group, inArg any) (*Value, any, e
|
||||
|
||||
d.AddChild(dv)
|
||||
if _, err := d.bitBuf.SeekBits(dv.Range.Len, io.SeekCurrent); err != nil {
|
||||
d.IOPanic(err, "TryFieldFormat: SeekRel")
|
||||
d.IOPanic(err, name, "TryFieldFormat: SeekRel")
|
||||
}
|
||||
|
||||
return dv, v, err
|
||||
@ -1024,7 +1024,7 @@ func (d *D) TryFieldFormat(name string, group *Group, inArg any) (*Value, any, e
|
||||
func (d *D) FieldFormat(name string, group *Group, inArg any) (*Value, any) {
|
||||
dv, v, err := d.TryFieldFormat(name, group, inArg)
|
||||
if dv == nil || dv.Errors() != nil {
|
||||
d.IOPanic(err, "FieldFormat: TryFieldFormat")
|
||||
d.IOPanic(err, name, "FieldFormat: TryFieldFormat")
|
||||
}
|
||||
return dv, v
|
||||
}
|
||||
@ -1054,7 +1054,7 @@ func (d *D) TryFieldFormatLen(name string, nBits int64, group *Group, inArg any)
|
||||
|
||||
d.AddChild(dv)
|
||||
if _, err := d.bitBuf.SeekBits(nBits, io.SeekCurrent); err != nil {
|
||||
d.IOPanic(err, "TryFieldFormatLen: SeekRel")
|
||||
d.IOPanic(err, name, "TryFieldFormatLen: SeekRel")
|
||||
}
|
||||
|
||||
return dv, v, err
|
||||
@ -1063,7 +1063,7 @@ func (d *D) TryFieldFormatLen(name string, nBits int64, group *Group, inArg any)
|
||||
func (d *D) FieldFormatLen(name string, nBits int64, group *Group, inArg any) (*Value, any) {
|
||||
dv, v, err := d.TryFieldFormatLen(name, nBits, group, inArg)
|
||||
if dv == nil || dv.Errors() != nil {
|
||||
d.IOPanic(err, "FieldFormatLen: TryFieldFormatLen")
|
||||
d.IOPanic(err, name, "FieldFormatLen: TryFieldFormatLen")
|
||||
}
|
||||
return dv, v
|
||||
}
|
||||
@ -1100,7 +1100,7 @@ func (d *D) TryFieldFormatRange(name string, firstBit int64, nBits int64, group
|
||||
func (d *D) FieldFormatRange(name string, firstBit int64, nBits int64, group *Group, inArg any) (*Value, any) {
|
||||
dv, v, err := d.TryFieldFormatRange(name, firstBit, nBits, group, inArg)
|
||||
if dv == nil || dv.Errors() != nil {
|
||||
d.IOPanic(err, "FieldFormatRange: TryFieldFormatRange")
|
||||
d.IOPanic(err, name, "FieldFormatRange: TryFieldFormatRange")
|
||||
}
|
||||
|
||||
return dv, v
|
||||
@ -1130,7 +1130,7 @@ func (d *D) TryFieldFormatBitBuf(name string, br bitio.ReaderAtSeeker, group *Gr
|
||||
func (d *D) FieldFormatBitBuf(name string, br bitio.ReaderAtSeeker, group *Group, inArg any) (*Value, any) {
|
||||
dv, v, err := d.TryFieldFormatBitBuf(name, br, group, inArg)
|
||||
if dv == nil || dv.Errors() != nil {
|
||||
d.IOPanic(err, "FieldFormatBitBuf: TryFieldFormatBitBuf")
|
||||
d.IOPanic(err, name, "FieldFormatBitBuf: TryFieldFormatBitBuf")
|
||||
}
|
||||
|
||||
return dv, v
|
||||
@ -1141,7 +1141,7 @@ func (d *D) FieldFormatBitBuf(name string, br bitio.ReaderAtSeeker, group *Group
|
||||
func (d *D) FieldRootBitBuf(name string, br bitio.ReaderAtSeeker, sms ...scalar.BitBufMapper) *Value {
|
||||
brLen, err := bitiox.Len(br)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "br Len")
|
||||
d.IOPanic(err, name, "br Len")
|
||||
}
|
||||
|
||||
v := &Value{}
|
||||
@ -1188,17 +1188,17 @@ func (d *D) FieldStructRootBitBufFn(name string, br bitio.ReaderAtSeeker, fn fun
|
||||
func (d *D) FieldFormatReaderLen(name string, nBits int64, fn func(r io.Reader) (io.ReadCloser, error), group *Group) (*Value, any) {
|
||||
br, err := d.TryBitBufLen(nBits)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "FieldFormatReaderLen: BitBufLen")
|
||||
d.IOPanic(err, name, "FieldFormatReaderLen: BitBufLen")
|
||||
}
|
||||
|
||||
bbBR := bitio.NewIOReader(br)
|
||||
r, err := fn(bbBR)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "FieldFormatReaderLen: fn")
|
||||
d.IOPanic(err, name, "FieldFormatReaderLen: fn")
|
||||
}
|
||||
rBuf, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "FieldFormatReaderLen: ReadAll")
|
||||
d.IOPanic(err, name, "FieldFormatReaderLen: ReadAll")
|
||||
}
|
||||
rBR := bitio.NewBitReader(rBuf, -1)
|
||||
|
||||
@ -1245,7 +1245,7 @@ func (d *D) FieldReaderRange(name string, startBit int64, nBits int64, fn func(r
|
||||
func (d *D) FieldReaderRangeFormat(name string, startBit int64, nBits int64, fn func(r io.Reader) io.Reader, group *Group, inArg any) (int64, bitio.ReaderAtSeeker, *Value, any) {
|
||||
cz, rBR, dv, v, err := d.TryFieldReaderRangeFormat(name, startBit, nBits, fn, group, inArg)
|
||||
if err != nil {
|
||||
d.IOPanic(err, "TryFieldReaderRangeFormat")
|
||||
d.IOPanic(err, name, "TryFieldReaderRangeFormat")
|
||||
}
|
||||
return cz, rBR, dv, v
|
||||
}
|
||||
@ -1268,7 +1268,7 @@ func (d *D) TryFieldValue(name string, fn func() (*Value, error)) (*Value, error
|
||||
func (d *D) FieldValue(name string, fn func() *Value) *Value {
|
||||
v, err := d.TryFieldValue(name, func() (*Value, error) { return fn(), nil })
|
||||
if err != nil {
|
||||
d.IOPanic(err, "FieldValue: TryFieldValue")
|
||||
d.IOPanic(err, name, "FieldValue: TryFieldValue")
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -26,7 +26,7 @@ import (
|
||||
func (d *D) Field{{$name}}ScalarFn(name string, fn func(d *D) scalar.{{$name}}, sms ...scalar.{{$name}}Mapper) {{$t.go_type}} {
|
||||
v, err := d.TryFieldScalar{{$name}}Fn(name, func(d *D) (scalar.{{$name}}, error) { return fn(d), nil }, sms...)
|
||||
if err != nil {
|
||||
panic(IOError{Err: err, Name: name, Op: "{{$name}}", Pos: d.Pos()})
|
||||
d.IOPanic(err, name, "{{$name}}")
|
||||
}
|
||||
return v.Actual
|
||||
}
|
||||
@ -48,7 +48,7 @@ import (
|
||||
func (d *D) FieldScalar{{$name}}Fn(name string, fn func(d *D) scalar.{{$name}}, sms ...scalar.{{$name}}Mapper) *scalar.{{$name}} {
|
||||
v, err := d.TryFieldScalar{{$name}}Fn(name, func(d *D) (scalar.{{$name}}, error) { return fn(d), nil }, sms...)
|
||||
if err != nil {
|
||||
panic(IOError{Err: err, Name: name, Op: "{{$name}}", Pos: d.Pos()})
|
||||
d.IOPanic(err, name, "{{$name}}")
|
||||
}
|
||||
return v
|
||||
}
|
||||
@ -181,7 +181,7 @@ import (
|
||||
func (d *D) {{$r.name}}{{replace $v.name "$n" $n}}({{$v.params}}) {{$t.go_type}} {
|
||||
v, err := {{replace $v.call "$n" $n}}
|
||||
if err != nil {
|
||||
panic(IOError{Err: err, Op: "{{$r.name}}{{replace $v.name "$n" $n}}", Pos: d.Pos()})
|
||||
d.IOPanic(err, "", "{{$r.name}}{{replace $v.name "$n" $n}}")
|
||||
}
|
||||
return v
|
||||
}
|
||||
@ -202,7 +202,7 @@ import (
|
||||
func (d *D) FieldScalar{{$r.name}}{{replace $v.name "$n" $n}}(name string{{if $v.params}}, {{$v.params}}{{end}}, sms ...scalar.{{$r.type}}Mapper) *scalar.{{$r.type}} {
|
||||
s, err := d.TryFieldScalar{{$r.name}}{{replace $v.name "$n" $n}}(name{{if $v.args}}, {{$v.args}}{{end}}, sms...)
|
||||
if err != nil {
|
||||
panic(IOError{Err: err, Name: name, Op: "{{$r.name}}{{replace $v.name "$n" $n}}", Pos: d.Pos()})
|
||||
d.IOPanic(err, name, "{{$r.name}}{{replace $v.name "$n" $n}}")
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user