Skip to content

Add custom ExecError - #5184

Merged
helderco merged 6 commits into
dagger:mainfrom
helderco:helder/dag-290-error-types
May 25, 2023
Merged

helderco merged 6 commits into
dagger:mainfrom
helderco:helder/dag-290-error-types

Conversation

@helderco

@helderco helderco commented May 23, 2023 •

Copy link
Copy Markdown
Contributor

Fixes #4700

This adds a custom ExecError that allows you to access properties of an command execution error directly, without having to parse them using regex or similar, from the error message.

The old message format is still used, with included stdout and stderr when printing the error for visibility.

Examples

Use case: Handle a command execution error in a specific way, but let other kinds of errors bubble up.

Go

_, err := ctr.sync(ctx)
var e *dagger.ExecError
if errors.As(err, &e) {
    // e.Message()
    // e.ExitCode
    // e.Stdout
    // e.Stderr
    // e.Cmd
} else if err != nil {
    return err
}

Reference

Python

try:
    await ctr
except dagger.ExecError as e:
    # e.message
    # e.exit_code
    # e.stdout
    # e.stderr
    # e.cmd
    ...

Node.js

try {
    await ctr.sync()
} catch (e) {
    if (e instanceof ExecError) {
        // e.message
        // e.exitCode
        // e.stdout
        // e.stderr
        // e.cmd
    } else {
        throw e
    }
}

Reference

\cc @sipsma @kjuulh

@helderco helderco added the kind/breaking Breaking Change label May 23, 2023
Comment thread sdk/go/error.go Resolved
@helderco
helderco force-pushed the helder/dag-290-error-types branch from 12f13ab to 5485505 Compare May 24, 2023 13:03
@helderco
helderco marked this pull request as ready for review May 24, 2023 15:57
@helderco
helderco force-pushed the helder/dag-290-error-types branch from f4603c9 to d0f09f9 Compare May 24, 2023 17:33
@helderco helderco removed the kind/breaking Breaking Change label May 24, 2023
@sipsma

sipsma commented May 24, 2023

Copy link
Copy Markdown
Contributor

Also cc @matiasinsaurralde, you mentioned recently that it might be nice to have more structured errors like this

@kjuulh

kjuulh commented May 24, 2023

Copy link
Copy Markdown
Contributor

The rust sdk should work fine once generated with this new error type. Will have to test it out though

Comment thread core/gateway.go Resolved
@helderco
helderco force-pushed the helder/dag-290-error-types branch from ba9db00 to 624e214 Compare May 24, 2023 23:25
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.

Error types

3 participants