diff options
author | Wim <wim@42.be> | 2023-08-05 20:43:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-05 20:43:19 +0200 |
commit | 56e7bd01ca09ad52b0c4f48f146a20a4f1b78696 (patch) | |
tree | b1355645342667209263cbd355dc0b4254f1e8fe /vendor/github.com/mattermost/mattermost-server/v5/utils | |
parent | 9459495484d6e06a3d46de64fccd8d06f7ccc72c (diff) | |
download | matterbridge-msglm-master.tar.gz matterbridge-msglm-master.tar.bz2 matterbridge-msglm-master.zip |
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v5/utils')
-rw-r--r-- | vendor/github.com/mattermost/mattermost-server/v5/utils/jsonutils/json.go | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v5/utils/jsonutils/json.go b/vendor/github.com/mattermost/mattermost-server/v5/utils/jsonutils/json.go deleted file mode 100644 index 9d5e7872..00000000 --- a/vendor/github.com/mattermost/mattermost-server/v5/utils/jsonutils/json.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. - -package jsonutils - -import ( - "bytes" - "encoding/json" - - "github.com/pkg/errors" -) - -type HumanizedJSONError struct { - Err error - Line int - Character int -} - -func (e *HumanizedJSONError) Error() string { - return e.Err.Error() -} - -// HumanizeJSONError extracts error offsets and annotates the error with useful context -func HumanizeJSONError(err error, data []byte) error { - if syntaxError, ok := err.(*json.SyntaxError); ok { - return NewHumanizedJSONError(syntaxError, data, syntaxError.Offset) - } else if unmarshalError, ok := err.(*json.UnmarshalTypeError); ok { - return NewHumanizedJSONError(unmarshalError, data, unmarshalError.Offset) - } else { - return err - } -} - -func NewHumanizedJSONError(err error, data []byte, offset int64) *HumanizedJSONError { - if err == nil { - return nil - } - - if offset < 0 || offset > int64(len(data)) { - return &HumanizedJSONError{ - Err: errors.Wrapf(err, "invalid offset %d", offset), - } - } - - lineSep := []byte{'\n'} - - line := bytes.Count(data[:offset], lineSep) + 1 - lastLineOffset := bytes.LastIndex(data[:offset], lineSep) - character := int(offset) - (lastLineOffset + 1) + 1 - - return &HumanizedJSONError{ - Line: line, - Character: character, - Err: errors.Wrapf(err, "parsing error at line %d, character %d", line, character), - } -} |