From a611f9fd7cd971ab4ebf04e3fa76377af442e992 Mon Sep 17 00:00:00 2001 From: gutmet Date: Mon, 27 Apr 2020 20:09:58 +0200 Subject: [PATCH] better error message for byte field of unknown size --- laymanshex.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/laymanshex.go b/laymanshex.go index 84d71c6..21d1f88 100644 --- a/laymanshex.go +++ b/laymanshex.go @@ -16,7 +16,11 @@ import ( func optPanic(msg string, err error) { if err != nil { - panic(errors.New(msg + ": " + err.Error())) + if msg != "" { + panic(msg + ": " + err.Error()) + } else { + panic(err) + } } } @@ -174,7 +178,11 @@ func (part *filePart) setByteFieldHandling(assignments map[string]*formatAssignm ass.used = true err = nil } else { - err = errors.New("Could neither parse size to int64 nor obtain value from -fvar") + msg := "byte field: could neither parse size to int64 nor obtain value from -fvar" + if part.name != "" { + msg += " definition " + part.name + } + err = errors.New(msg) } } optPanic(part.name, err)