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

failure v2 #50

Merged
merged 54 commits into from
Apr 19, 2024
Merged

failure v2 #50

merged 54 commits into from
Apr 19, 2024

Conversation

morikuni
Copy link
Owner

@morikuni morikuni commented Apr 18, 2024

Please check docs/v1-to-v2.md for migration.
If there were something unclear or found issues, feel free to open issue or contact me on X https://twitter.com/inukirom.

What's New

Remarkable changes with v2.

Simple error chain structure

v2 has only one struct to wrap errors rather than wrapping errors for each wrapper struct.

In v1 error chain structure was like

withCode {
    code,
    withMessage {
        message,
        withCallStack {
            callstack,
            err,
        },
    },
}

But in v2 error chain structure will be like

Failure {
    fields {
        KeyCode: code,
        KeyMessage: message,
        KeyCallStack: callstack,
    },
    Failure {
        fields {
            KeyCallStack: callstack,
        },
        err,
    },
}

So no longer need wrapping too much times for each additional data.
You can simply add any key-value data in failure.

Arbitrary error code type

v1 had been requested Code interface for error codes:

type Code interface {
	// ErrorCode returns an error code in string representation.
	ErrorCode() string
}

But now, any comparable types can be used as error code in v2:

type Code comparable

So, you can use gRPC error code google.golang.org/grpc/codes with failure!

failure.New(codes.InvalidArgument)

@morikuni morikuni merged commit 2551069 into main Apr 19, 2024
1 check passed
@morikuni morikuni deleted the v2 branch April 19, 2024 00:27
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.

1 participant