Skip to content

Commit

Permalink
cue: remove error type aliases
Browse files Browse the repository at this point in the history
these were left over from a refactoring

Change-Id: Ibeb934c79fdee708bc74729fc597dce274c2ca60
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9345
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Apr 8, 2021
1 parent 6a1ae9c commit e440183
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
13 changes: 3 additions & 10 deletions cue/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,18 @@ func (e *valueError) Path() (a []string) {
return e.v.appendPath(nil)
}

type errCode = adt.ErrorCode

const (
codeNotExist = adt.NotExistError
codeIncomplete = adt.IncompleteError
)

var errNotExists = &adt.Bottom{
Code: codeNotExist,
Code: adt.NotExistError,
Err: errors.Newf(token.NoPos, "undefined value"),
}

func (idx *index) mkErr(src adt.Node, args ...interface{}) *adt.Bottom {
var e *adt.Bottom
var code errCode = -1
var code adt.ErrorCode = -1
outer:
for i, a := range args {
switch x := a.(type) {
case errCode:
case adt.ErrorCode:
code = x
case *adt.Bottom:
e = adt.CombineErrors(nil, e, x)
Expand Down
2 changes: 1 addition & 1 deletion cue/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ outer:
x = &adt.Bottom{Err: err.Error}
} else {
// TODO: better message.
x = v.idx.mkErr(n, codeNotExist, "value %q not found", sel.sel)
x = v.idx.mkErr(n, adt.NotExistError, "value %q not found", sel.sel)
}
v := makeValue(v.idx, n)
return newErrValue(v, x)
Expand Down
12 changes: 6 additions & 6 deletions cue/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (o *structValue) Lookup(key string) Value {
if i == len {
// TODO: better message.
ctx := o.ctx
x := ctx.mkErr(o.obj, codeNotExist, "value %q not found", key)
x := ctx.mkErr(o.obj, adt.NotExistError, "value %q not found", key)
return newErrValue(o.v, x)
}
return newChildValue(o, i)
Expand Down Expand Up @@ -179,7 +179,7 @@ func toMarshalErr(v Value, b *adt.Bottom) error {
return &marshalError{v.toErr(b), b}
}

func marshalErrf(v Value, src adt.Node, code errCode, msg string, args ...interface{}) error {
func marshalErrf(v Value, src adt.Node, code adt.ErrorCode, msg string, args ...interface{}) error {
arguments := append([]interface{}{code, msg}, args...)
b := v.idx.mkErr(src, arguments...)
return toMarshalErr(v, b)
Expand Down Expand Up @@ -880,10 +880,10 @@ func (v Value) marshalJSON() (b []byte, err error) {
x := v.eval(ctx)

if _, ok := x.(adt.Resolver); ok {
return nil, marshalErrf(v, x, codeIncomplete, "value %q contains unresolved references", ctx.str(x))
return nil, marshalErrf(v, x, adt.IncompleteError, "value %q contains unresolved references", ctx.str(x))
}
if !adt.IsConcrete(x) {
return nil, marshalErrf(v, x, codeIncomplete, "cannot convert incomplete value %q to JSON", ctx.str(x))
return nil, marshalErrf(v, x, adt.IncompleteError, "cannot convert incomplete value %q to JSON", ctx.str(x))
}

// TODO: implement marshalles in value.
Expand Down Expand Up @@ -1139,7 +1139,7 @@ func (v Value) Exists() bool {
return false
}
if err, ok := v.v.BaseValue.(*adt.Bottom); ok {
return err.Code != codeNotExist
return err.Code != adt.NotExistError
}
return true
}
Expand All @@ -1160,7 +1160,7 @@ func (v Value) checkKind(ctx *context, want adt.Kind) *adt.Bottom {
ctx.opCtx.Str(x), k, want)
}
if !adt.IsConcrete(x) {
return ctx.mkErr(x, codeIncomplete, "non-concrete value %v", k)
return ctx.mkErr(x, adt.IncompleteError, "non-concrete value %v", k)
}
}
return nil
Expand Down

0 comments on commit e440183

Please sign in to comment.