From af9ececb36386a0d2c86364695d36b43e7e87e0e Mon Sep 17 00:00:00 2001 From: "liuqiang.06" Date: Tue, 9 Jul 2024 19:35:47 +0800 Subject: [PATCH] chore: add more friendly warnings --- ast/error.go | 2 +- internal/decoder/errors/errors.go | 2 +- internal/encoder/vars/errors.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ast/error.go b/ast/error.go index 00a04468e..73b7af0b8 100644 --- a/ast/error.go +++ b/ast/error.go @@ -79,7 +79,7 @@ func (self SyntaxError) description() string { /* check for empty source */ if self.Src == "" { - return fmt.Sprintf("no sources available: %#v", self) + return fmt.Sprintf("no sources available, the input json is empty: %#v", self) } /* prevent slicing before the beginning */ diff --git a/internal/decoder/errors/errors.go b/internal/decoder/errors/errors.go index ae59ce169..9f05e8b6a 100644 --- a/internal/decoder/errors/errors.go +++ b/internal/decoder/errors/errors.go @@ -46,7 +46,7 @@ func (self SyntaxError) Description() string { func (self SyntaxError) description() string { /* check for empty source */ if self.Src == "" { - return fmt.Sprintf("no sources available: %#v", self) + return fmt.Sprintf("no sources available, the input json is empty: %#v", self) } p, x, q, y := calcBounds(len(self.Src), self.Pos) diff --git a/internal/encoder/vars/errors.go b/internal/encoder/vars/errors.go index 2e7622421..77919c44a 100644 --- a/internal/encoder/vars/errors.go +++ b/internal/encoder/vars/errors.go @@ -58,7 +58,7 @@ const ( func GoPanic(code int, val unsafe.Pointer) { switch(code){ case PanicNilPointerOfNonEmptyString: - panic(fmt.Sprintf("val: %#v has nil pointer while its length is not zero!", (*rt.GoString)(val))) + panic(fmt.Sprintf("val: %#v has nil pointer while its length is not zero!\nThis is a nil pointer exception (NPE) problem. There might be a data race issue. It is recommended to execute the tests related to the code with the `-race` compile flag to detect the problem.", (*rt.GoString)(val))) default: panic("encoder error!") }