mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-13 11:53:38 -06:00
039c7bdd02
- Refactor error codes to use strings instead of ints. - Simplify error messages throughout. - Ensure location set on all expressions. There were a couple locations in the parser/compiler where locations were not being set. - Fallback to rule location in topdown in case location not set. This ensures that users get useful locations for API requests with paths that refer to virtual docs exactly. Also add Find function to ast.Value. Useful for extracting values dynamically. Eventually can support JSON pointers. Fixes #237
39 lines
826 B
Go
39 lines
826 B
Go
// Copyright 2016 The OPA Authors. All rights reserved.
|
|
// Use of this source code is governed by an Apache2
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package repl
|
|
|
|
import "fmt"
|
|
|
|
// Error is the error type returned by the REPL.
|
|
type Error struct {
|
|
Code string
|
|
Message string
|
|
}
|
|
|
|
func (err *Error) Error() string {
|
|
return fmt.Sprintf("code %v: %v", err.Code, err.Message)
|
|
}
|
|
|
|
const (
|
|
// BadArgsErr indicates bad arguments were provided to a built-in REPL
|
|
// command.
|
|
BadArgsErr string = "bad arguments"
|
|
)
|
|
|
|
func newBadArgsErr(f string, a ...interface{}) *Error {
|
|
return &Error{
|
|
Code: BadArgsErr,
|
|
Message: fmt.Sprintf(f, a...),
|
|
}
|
|
}
|
|
|
|
// stop is returned by the 'exit' command to indicate to the REPL that it should
|
|
// break and return.
|
|
type stop struct{}
|
|
|
|
func (stop) Error() string {
|
|
return "<stop>"
|
|
}
|