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