Skip to content

Commit 8bfd443

Browse files
committed
Add method for getting error string without unwrapping for backwards compatibility
Signed-off-by: Dave Crighton <dave.crighton@kaleido.io>
1 parent 854d2a7 commit 8bfd443

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

pkg/abi/abi.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ func SanitizeBinaryString(raw []byte) string {
378378
}
379379

380380
func FormatErrorStringCtx(ctx context.Context, e *Entry, cv *ComponentValue) string {
381+
if e == nil || cv == nil {
382+
return ""
383+
}
381384
var ok bool
382385
var parsed []interface{}
383386
if res, err := NewSerializer().

pkg/abi/reverterror.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ func (r *RevertError) String() string {
170170
return b.String()
171171
}
172172

173+
// ErrorString returns the formatted error at this level only, e.g.
174+
// Error("not enough funds") or MyCustomError("0x1234","-100").
175+
// Unlike String(), it does not walk the Nested chain — use it when
176+
// you need the single-level description without recursive unwrapping.
177+
func (r *RevertError) ErrorString() string {
178+
if r == nil {
179+
return ""
180+
}
181+
return FormatErrorStringCtx(context.Background(), r.ErrorEntry, r.cv)
182+
}
183+
173184
// Signature returns the ABI signature of the error at this level,
174185
// e.g. "Error(string)" or "AnError(string,uint256)".
175186
func (r *RevertError) Signature() (string, error) {

0 commit comments

Comments
 (0)