-
Notifications
You must be signed in to change notification settings - Fork 215
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
Make errors support verbose formatting to print wrapped errors #1396
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1245,3 +1245,44 @@ func Test_convertFailureToError_SaveFailure(t *testing.T) { | |
require.Equal("SomeJavaException", f2.GetCause().GetApplicationFailureInfo().GetType()) | ||
require.Equal(true, f2.GetCause().GetApplicationFailureInfo().GetNonRetryable()) | ||
} | ||
|
||
func Test_verbose_error_formatting(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
err error | ||
expected string | ||
}{ | ||
{ | ||
name: "WorkflowExecutionError", | ||
err: NewWorkflowExecutionError("wid", "rid", "workflowType", newWorkflowPanicError("test message", "stack trace")), | ||
expected: "stack trace\ntest message\nworkflow execution error (type: workflowType, workflowID: wid, runID: rid): test message", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems odd to show inner error information before outer error information There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I basically copied the behavior from github.com/pkg/errors - I did also think the same but for consistency it seemed like the best approach |
||
}, | ||
{ | ||
name: "ApplicationError", | ||
err: NewApplicationError("test message", "customType", true, errors.New("cause error"), "details", 2208), | ||
expected: "cause error\ntest message (type: customType, retryable: false): cause error", | ||
}, | ||
{ | ||
name: "TimeoutError", | ||
err: NewTimeoutError("timeout", enumspb.TIMEOUT_TYPE_START_TO_CLOSE, errors.New("cause error")), | ||
expected: "cause error\ntimeout (type: StartToClose): cause error", | ||
}, | ||
{ | ||
name: "ServerError", | ||
err: NewServerError("message", true, errors.New("cause error")), | ||
expected: "cause error\nmessage: cause error", | ||
}, | ||
{ | ||
name: "ChildWorkflowExecutionError", | ||
err: NewChildWorkflowExecutionError("namespace", "wID", "rID", "wfType", 8, 22, enumspb.RETRY_STATE_NON_RETRYABLE_FAILURE, NewApplicationError("test message", "customType", true, errors.New("cause error"))), | ||
expected: "cause error\ntest message (type: customType, retryable: false): cause error\nchild workflow execution error (type: wfType, workflowID: wID, runID: rID, initiatedEventID: 8, startedEventID: 22): test message (type: customType, retryable: false): cause error", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
str := fmt.Sprintf("%+v", test.err) | ||
require.Equal(t, test.expected, str) | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fear the future proof-ness of this. If Go adds new print flags that'd work for errors, we'd silently not support them.
I wonder if it'd be better to change where you're formatting these errors to handle more advanced types instead of adding a formatting feature to a few of the errors here. I think that gives you the most flexibility instead of assuming exactly what people want when
%+v
is put (you want stack trace, but another might want struct fields). We tend to put accessors on the errors for users to extract and display the way they prefer.(having said that, I'm not completely against the change, I think it just makes too many assumptions of what users may want to see instead of encouraging them to extract the information themselves when they're displaying)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right it might be different what people want - I just copied the behavior from pkg/errors since that seems to be what a lot of people (including myself) are used to. I'd personally say that
%+v
means max verbose, so dump anything that can be dumped, but again that might be a personal preference...