MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / convertJSONError

Function convertJSONError

dgraph/cmd/alpha/http.go:771–795  ·  view source on GitHub ↗

convertJSONError adds line and character information to the JSON error. Idea taken from: https://bit.ly/2moFIVS

(input string, err error)

Source from the content-addressed store, hash-verified

769// convertJSONError adds line and character information to the JSON error.
770// Idea taken from: https://bit.ly/2moFIVS
771func convertJSONError(input string, err error) error {
772 if err == nil {
773 return nil
774 }
775
776 if jsonError, ok := err.(*json.SyntaxError); ok {
777 line, character, lcErr := jsonLineAndChar(input, int(jsonError.Offset))
778 if lcErr != nil {
779 return err
780 }
781 return errors.Errorf("Error parsing JSON at line %d, character %d: %v\n", line, character,
782 jsonError.Error())
783 }
784
785 if jsonError, ok := err.(*json.UnmarshalTypeError); ok {
786 line, character, lcErr := jsonLineAndChar(input, int(jsonError.Offset))
787 if lcErr != nil {
788 return err
789 }
790 return errors.Errorf("Error parsing JSON at line %d, character %d: %v\n", line, character,
791 jsonError.Error())
792 }
793
794 return err
795}
796
797func jsonLineAndChar(input string, offset int) (line int, character int, err error) {
798 lf := rune(0x0A)

Callers 2

queryHandlerFunction · 0.85
mutationHandlerFunction · 0.85

Calls 3

jsonLineAndCharFunction · 0.85
ErrorfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected