-
Notifications
You must be signed in to change notification settings - Fork 47
/
error.go
56 lines (44 loc) · 1.07 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
Use of this source code is governed by a MIT license that can be found in the LICENSE file.
*/
package selector
import (
"encoding/json"
"fmt"
)
const (
errExpectedNonEmptyKey = "expected non-empty key"
)
// Error is a hard alias to string.
type Error string
// Error implements `error`
func (e Error) Error() string {
return string(e)
}
// MarshalJSON implements json.Marshaler.
func (e Error) MarshalJSON() ([]byte, error) {
return json.Marshal(string(e))
}
// ParseError is a specific parse error.
type ParseError struct {
Err error
Input string
Position int
Message string
}
// Class implements ex.ClassProvider.
func (pe ParseError) Class() error {
return pe.Err
}
// Unwrap implements unwrap.
func (pe ParseError) Unwrap() error {
return pe.Err
}
// String implements error.
func (pe ParseError) Error() string {
if pe.Message != "" {
return fmt.Sprintf("%q:0:%d: %v; %s", pe.Input, pe.Position, pe.Err, pe.Message)
}
return fmt.Sprintf("%q:0:%d: %v", pe.Input, pe.Position, pe.Err)
}