git.lukeshu.com/go/lowmemjson@v0.3.9-0.20230723050957-72f6d13f6fb2/compat/json/borrowed_misc.go (about) 1 // Copyright 2010 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 // 5 // SPDX-License-Identifier: BSD-3-Clause 6 7 package json 8 9 import ( 10 "reflect" 11 ) 12 13 // A SyntaxError is a description of a JSON syntax error. 14 // Unmarshal will return a SyntaxError if the JSON can't be parsed. 15 type SyntaxError struct { 16 msg string // description of error 17 Offset int64 // error occurred after reading Offset bytes 18 } 19 20 func (e *SyntaxError) Error() string { return e.msg } 21 22 // A MarshalerError represents an error from calling a MarshalJSON or MarshalText method. 23 type MarshalerError struct { 24 Type reflect.Type 25 Err error 26 sourceFunc string 27 } 28 29 func (e *MarshalerError) Error() string { 30 srcFunc := e.sourceFunc 31 if srcFunc == "" { 32 srcFunc = "MarshalJSON" 33 } 34 return "json: error calling " + srcFunc + 35 " for type " + e.Type.String() + 36 ": " + e.Err.Error() 37 } 38 39 // Unwrap returns the underlying error. 40 func (e *MarshalerError) Unwrap() error { return e.Err }