cue icon indicating copy to clipboard operation
cue copied to clipboard

cue: provide a way of creating an error Value

Open rogpeppe opened this issue 1 year ago • 0 comments

The cue API extensively uses the capability to return Values holding an error rather than return (Value, error) pairs. However, there is no way to use the API to create a Value holding an arbitrary error. This means that it's not easily possible for non-core packages to provide a similar API or to wrap the cue API while preserving the same style of interface.

We should provide this capability, for example by adding a method like this:

package cue

// Error returns a new Value holding the given error.
func (ctx *Context) Error(err error) Value

Another possibility might be to overload Context.Encode: if its argument implements error, it could return an error value.

rogpeppe avatar Oct 13 '24 09:10 rogpeppe