cuelang.org/go@v0.10.1/internal/core/compile/errors.go (about) 1 // Copyright 2020 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 compile 16 17 import ( 18 "strings" 19 20 "cuelang.org/go/cue/ast" 21 "cuelang.org/go/cue/errors" 22 "cuelang.org/go/cue/token" 23 ) 24 25 var _ errors.Error = &compilerError{} 26 27 type compilerError struct { 28 n ast.Node 29 path []string 30 errors.Message 31 } 32 33 func (e *compilerError) Position() token.Pos { return e.n.Pos() } 34 func (e *compilerError) InputPositions() []token.Pos { return nil } 35 func (e *compilerError) Path() []string { return e.path } 36 func (e *compilerError) Error() string { 37 pos := e.n.Pos() 38 // Import cycles deserve special treatment. 39 if pos.IsValid() { 40 // Omit import stack. The full path to the file where the error 41 // is the most important thing. 42 return pos.String() + ": " + e.Message.Error() 43 } 44 if len(e.path) == 0 { 45 return e.Message.Error() 46 } 47 return strings.Join(e.path, ".") + ": " + e.Message.Error() 48 }