summaryrefslogtreecommitdiff
path: root/vendor/github.com/bytedance/sonic/internal/decoder/errors.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2023-11-27 13:15:03 +0000
committerLibravatar GitHub <noreply@github.com>2023-11-27 13:15:03 +0000
commit66b77acb1c8b86f0be3836ccaf31683c0bfa317a (patch)
tree9a255a8ea8ef97229b6d75d17de45bdac1755be9 /vendor/github.com/bytedance/sonic/internal/decoder/errors.go
parent[bugfix] Add Actor to outgoing poll vote Create; other fixes (#2384) (diff)
downloadgotosocial-66b77acb1c8b86f0be3836ccaf31683c0bfa317a.tar.xz
[chore]: Bump github.com/gin-contrib/cors from 1.4.0 to 1.5.0 (#2388)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/bytedance/sonic/internal/decoder/errors.go')
-rw-r--r--vendor/github.com/bytedance/sonic/internal/decoder/errors.go66
1 files changed, 38 insertions, 28 deletions
diff --git a/vendor/github.com/bytedance/sonic/internal/decoder/errors.go b/vendor/github.com/bytedance/sonic/internal/decoder/errors.go
index c905fdfb0..4453f5cfe 100644
--- a/vendor/github.com/bytedance/sonic/internal/decoder/errors.go
+++ b/vendor/github.com/bytedance/sonic/internal/decoder/errors.go
@@ -44,45 +44,55 @@ func (self SyntaxError) Description() string {
}
func (self SyntaxError) description() string {
- i := 16
- p := self.Pos - i
- q := self.Pos + i
-
/* check for empty source */
if self.Src == "" {
return fmt.Sprintf("no sources available: %#v", self)
}
+ p, x, q, y := calcBounds(len(self.Src), self.Pos)
+
+ /* compose the error description */
+ return fmt.Sprintf(
+ "at index %d: %s\n\n\t%s\n\t%s^%s\n",
+ self.Pos,
+ self.Message(),
+ self.Src[p:q],
+ strings.Repeat(".", x),
+ strings.Repeat(".", y),
+ )
+}
+
+func calcBounds(size int, pos int) (lbound int, lwidth int, rbound int, rwidth int) {
+ if pos >= size || pos < 0 {
+ return 0, 0, size, 0
+ }
+
+ i := 16
+ lbound = pos - i
+ rbound = pos + i
+
/* prevent slicing before the beginning */
- if p < 0 {
- p, q, i = 0, q - p, i + p
+ if lbound < 0 {
+ lbound, rbound, i = 0, rbound - lbound, i + lbound
}
/* prevent slicing beyond the end */
- if n := len(self.Src); q > n {
- n = q - n
- q = len(self.Src)
+ if n := size; rbound > n {
+ n = rbound - n
+ rbound = size
/* move the left bound if possible */
- if p > n {
+ if lbound > n {
i += n
- p -= n
+ lbound -= n
}
}
/* left and right length */
- x := clamp_zero(i)
- y := clamp_zero(q - p - i - 1)
+ lwidth = clamp_zero(i)
+ rwidth = clamp_zero(rbound - lbound - i - 1)
- /* compose the error description */
- return fmt.Sprintf(
- "at index %d: %s\n\n\t%s\n\t%s^%s\n",
- self.Pos,
- self.Message(),
- self.Src[p:q],
- strings.Repeat(".", x),
- strings.Repeat(".", y),
- )
+ return
}
func (self SyntaxError) Message() string {
@@ -107,16 +117,19 @@ var stackOverflow = &json.UnsupportedValueError {
Value : reflect.ValueOf("..."),
}
-//go:nosplit
func error_wrap(src string, pos int, code types.ParsingError) error {
- return SyntaxError {
+ return *error_wrap_heap(src, pos, code)
+}
+
+//go:noinline
+func error_wrap_heap(src string, pos int, code types.ParsingError) *SyntaxError {
+ return &SyntaxError {
Pos : pos,
Src : src,
Code : code,
}
}
-//go:nosplit
func error_type(vt *rt.GoType) error {
return &json.UnmarshalTypeError{Type: vt.Pack()}
}
@@ -158,7 +171,6 @@ func (self MismatchTypeError) Description() string {
return fmt.Sprintf("Mismatch type %s with value %s %s", self.Type.String(), swithchJSONType(self.Src, self.Pos), se.description())
}
-//go:nosplit
func error_mismatch(src string, pos int, vt *rt.GoType) error {
return &MismatchTypeError {
Pos : pos,
@@ -167,12 +179,10 @@ func error_mismatch(src string, pos int, vt *rt.GoType) error {
}
}
-//go:nosplit
func error_field(name string) error {
return errors.New("json: unknown field " + strconv.Quote(name))
}
-//go:nosplit
func error_value(value string, vtype reflect.Type) error {
return &json.UnmarshalTypeError {
Type : vtype,