cuelang.org/go@v0.10.1/encoding/protobuf/errors.go (about) 1 // Copyright 2019 CUE Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package protobuf 16 17 import ( 18 "fmt" 19 "strings" 20 21 "cuelang.org/go/cue/token" 22 ) 23 24 // protobufError implements cue/Error 25 type protobufError struct { 26 path []string 27 pos token.Pos 28 err error 29 } 30 31 func (e *protobufError) Position() token.Pos { 32 return e.pos 33 } 34 35 func (e *protobufError) InputPositions() []token.Pos { 36 return nil 37 } 38 39 func (e *protobufError) Error() string { 40 if e.path == nil { 41 return fmt.Sprintf("protobuf: %s: %v", e.pos, e.err) 42 } 43 path := strings.Join(e.path, ".") 44 return fmt.Sprintf("protobuf: %s:%s: %v", e.pos, path, e.err) 45 } 46 47 func (e *protobufError) Path() []string { 48 return e.path 49 } 50 51 func (e *protobufError) Msg() (format string, args []interface{}) { 52 return "error parsing protobuf: %v", []interface{}{e.err} 53 }