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

(start) calls handler with error combiner instead #197

Merged
merged 1 commit into from
Jun 28, 2022
Merged

(start) calls handler with error combiner instead #197

merged 1 commit into from
Jun 28, 2022

Conversation

vito
Copy link
Owner

@vito vito commented Jun 28, 2022

previously (start) would call the handler with a bool indicating success. if the handler raised an error, it would actually be used to wrap the root error. this was always a little surprising.

meanwhile the handler had no way to access the root cause of the error, e.g. to log it using cli.WriteError(ctx, err), which I need to do in Bass Loop.

now the handler is called with a nullable combiner. if null, the thunk succeeded. if a combiner is present, it can be called to propagate the error to whoever waits on the thunk run.

to accomplish this a special Error combiner value has been introduced. it displays like <error: inner error msg> and when called returns the inner error.

the new implementation of (succeeds?) and (run) feel a bit cleaner: https://github.com/vito/bass/compare/anustart?expand=1#diff-23e0b46edf759eda1782b1de1613ddb63c137769ab51736200319a85ccde9d6c

side note: this is continuing along an "everything is a combiner" trend, which feels pretty intuitive for errors imo: errors are often wrapped, i.e. combined. so this combiner could be tweaked to take a wrapping message or something if we want. maybe a string and fields to avoid formatting and maintain symmetry with (error)?

i already shot my shot with the 'a nu start' joke, but it'd be better
applied here. oh well.

previously (start) would call the function with a bool indicating
success. if the handler raised an error, it would actually be used to
wrap the root error. this was always a little surprising.

meanwhile the handler had no way to access the root cause of the error,
e.g. to log it using cli.WriteError(ctx, err), which I need to do in
Bass Loop.

now the handler is called with a nullable combiner. if null, the thunk
succeeded. if a combiner is present, it can be called to propagate the
error to whoever waits on the thunk run.

to accomplish this a special Error combiner value has been introduced.
it displays like <error: inner error msg> and when called returns the
inner error.
@vito vito added enhancement New feature or request breaking Removes or replaces previously supported functionality labels Jun 28, 2022
@vito vito merged commit 4193102 into main Jun 28, 2022
@vito vito deleted the anustart branch June 28, 2022 03:00
@vito vito changed the title (start) calls handler with error combiner instead (start) calls handler with error combiner instead Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Removes or replaces previously supported functionality enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant