Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cue: provide a way of creating an error Value #3507

Open
rogpeppe opened this issue Oct 13, 2024 · 0 comments
Open

cue: provide a way of creating an error Value #3507

rogpeppe opened this issue Oct 13, 2024 · 0 comments
Labels
FeatureRequest New feature or request

Comments

@rogpeppe
Copy link
Member

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 rogpeppe added the FeatureRequest New feature or request label Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant