1 // Copyright 2017 Google Inc. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 // Error represents compiler errors and their location in the document.
23 // NewError creates an Error.
24 func NewError(context *Context, message string) *Error {
25 return &Error{Context: context, Message: message}
28 // Error returns the string value of an Error.
29 func (err *Error) Error() string {
30 if err.Context == nil {
31 return "ERROR " + err.Message
33 return "ERROR " + err.Context.Description() + " " + err.Message
36 // ErrorGroup is a container for groups of Error values.
37 type ErrorGroup struct {
41 // NewErrorGroupOrNil returns a new ErrorGroup for a slice of errors or nil if the slice is empty.
42 func NewErrorGroupOrNil(errors []error) error {
45 } else if len(errors) == 1 {
48 return &ErrorGroup{Errors: errors}
52 func (group *ErrorGroup) Error() string {
54 for i, err := range group.Errors {