Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
internal/protobuf: record position information
Browse files Browse the repository at this point in the history
for both errors and in the AST.

Removes the error type, which now implements the
standard CUE error conventions.

Change-Id: I7a4198a9cf9b38622f14f63df827f3f9730fe4b5
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2341
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Jun 25, 2019
1 parent e4ce243 commit fbcb339
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 85 deletions.
53 changes: 53 additions & 0 deletions internal/protobuf/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2019 CUE Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package protobuf

import (
"fmt"
"strings"

"cuelang.org/go/cue/token"
)

// protobufError implements cue/Error
type protobufError struct {
path []string
pos token.Pos
err error
}

func (e *protobufError) Position() token.Pos {
return e.pos
}

func (e *protobufError) InputPositions() []token.Pos {
return nil
}

func (e *protobufError) Error() string {
if e.path == nil {
return fmt.Sprintf("protobuf: %s: %v", e.pos, e.err)
}
path := strings.Join(e.path, ".")
return fmt.Sprintf("protobuf: %s:%s: %v", e.pos, path, e.err)
}

func (e *protobufError) Path() []string {
return e.path
}

func (e *protobufError) Msg() (format string, args []interface{}) {
return "error parsing protobuf: %v", []interface{}{e.err}
}
Loading

0 comments on commit fbcb339

Please sign in to comment.