diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-10 23:49:07 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-11 00:44:30 -0600 |
commit | ad9ac6d07ce1819260c2b7f090fd4fe742c80d9f (patch) | |
tree | ab6a607ea8575382c978f07de943ccf6c077de7c /lib/binstruct/errors.go | |
parent | 41ef03aabf8d6db4f926480fc5ddfec014e342d3 (diff) |
Fuzz btrfsitem, and by consequence improve binstruct errors
Diffstat (limited to 'lib/binstruct/errors.go')
-rw-r--r-- | lib/binstruct/errors.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/binstruct/errors.go b/lib/binstruct/errors.go new file mode 100644 index 0000000..3914ec7 --- /dev/null +++ b/lib/binstruct/errors.go @@ -0,0 +1,48 @@ +// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com> +// +// SPDX-License-Identifier: GPL-2.0-or-later + +package binstruct + +import ( + "fmt" + "reflect" +) + +type InvalidTypeError struct { + Type reflect.Type + Err error +} + +func (e *InvalidTypeError) Error() string { + return fmt.Sprintf("%v: %v", e.Type, e.Err) +} +func (e *InvalidTypeError) Unwrap() error { return e.Err } + +type UnmarshalError struct { + Type reflect.Type + Method string + Err error +} + +func (e *UnmarshalError) Error() string { + if e.Method == "" { + return fmt.Sprintf("%v: %v", e.Type, e.Err) + } + return fmt.Sprintf("(%v).%v: %v", e.Type, e.Method, e.Err) +} +func (e *UnmarshalError) Unwrap() error { return e.Err } + +type MarshalError struct { + Type reflect.Type + Method string + Err error +} + +func (e *MarshalError) Error() string { + if e.Method == "" { + return fmt.Sprintf("%v: %v", e.Type, e.Err) + } + return fmt.Sprintf("(%v).%v: %v", e.Type, e.Method, e.Err) +} +func (e *MarshalError) Unwrap() error { return e.Err } |