blob: 0c6756098547ad5e34f4aea5c9f88e5e987d7c1d [file] [log] [blame]
Marcel van Lohuizenfbcb3392019-06-25 11:02:21 +02001// 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
15package protobuf
16
17import (
18 "fmt"
19 "strings"
20
21 "cuelang.org/go/cue/token"
22)
23
24// protobufError implements cue/Error
25type protobufError struct {
26 path []string
27 pos token.Pos
28 err error
29}
30
31func (e *protobufError) Position() token.Pos {
32 return e.pos
33}
34
35func (e *protobufError) InputPositions() []token.Pos {
36 return nil
37}
38
39func (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
47func (e *protobufError) Path() []string {
48 return e.path
49}
50
51func (e *protobufError) Msg() (format string, args []interface{}) {
52 return "error parsing protobuf: %v", []interface{}{e.err}
53}