elvish/pkg/eval/compilation_error.go
2019-12-23 20:00:59 +00:00

21 lines
626 B
Go

package eval
import "github.com/elves/elvish/pkg/diag"
const compilationErrorType = "compilation error"
// NewCompilationError creates a new compilation error.
func NewCompilationError(message string, context diag.Context) error {
return &diag.Error{
Type: compilationErrorType, Message: message, Context: context}
}
// GetCompilationError returns a *diag.Error and true if the given error is a
// compilation error. Otherwise it returns nil and false.
func GetCompilationError(e error) (*diag.Error, bool) {
if e, ok := e.(*diag.Error); ok && e.Type == compilationErrorType {
return e, true
}
return nil, false
}