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

Enable casting custom errors in Go #5208

Merged
merged 1 commit into from Jun 1, 2023
Merged

Conversation

helderco
Copy link
Contributor

Follow up to #5184

Instead of having to unwrap a custom error:

var e *dagger.ExecError
if errors.As(err, &e) {
    return e.ExitCode
}

This allows directly casting:

if e, ok := err.(*dagger.ExecError); ok {
    return e.ExitCode
}

@helderco helderco requested a review from sipsma May 26, 2023 14:39
Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
@vito
Copy link
Contributor

vito commented May 31, 2023

I think this is fine, but folks should be using errors.As anyway; directly asserting on an error's type is super brittle. Was this causing issues?

@helderco
Copy link
Contributor Author

Was this causing issues?

No, it just seemed to me based on some shared bits of code that people might expect to do it that way. Not married to it in any way 🙂

@vito
Copy link
Contributor

vito commented May 31, 2023

All good! Just curious. :) It makes sense to me to not directly wrap our own expected errors anyhow.

@helderco helderco merged commit 679b27f into dagger:main Jun 1, 2023
18 checks passed
@helderco helderco deleted the sdk/go/error-cast branch June 1, 2023 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants