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

implement a custom error type for max transcode attempts #2729

Merged
merged 3 commits into from
Sep 13, 2023
Merged

Conversation

mjh1
Copy link
Contributor

@mjh1 mjh1 commented Jan 17, 2023

What does this pull request do? Explain your changes. (required)

Created a custom error and used multi-error wrapping to avoid needing to do any string matching in the error handling.

Specific updates (required)

How did you test each of these updates (required)

I modified the existing unit test.

Does this pull request close any open issues?

Checklist:

@codecov
Copy link

codecov bot commented Jan 18, 2023

Codecov Report

Merging #2729 (10426d3) into master (a231510) will decrease coverage by 0.36593%.
Report is 5 commits behind head on master.
The diff coverage is 100.00000%.

❗ Current head 10426d3 differs from pull request most recent head 005e441. Consider uploading reports for the commit 005e441 to get more accurate results

Impacted file tree graph

@@                 Coverage Diff                 @@
##              master       #2729         +/-   ##
===================================================
- Coverage   56.70668%   56.34075%   -0.36593%     
===================================================
  Files             88          88                 
  Lines          19160       19146         -14     
===================================================
- Hits           10865       10787         -78     
- Misses          7699        7767         +68     
+ Partials         596         592          -4     
Files Changed Coverage Δ
server/broadcast.go 77.46835% <100.00000%> (-0.08941%) ⬇️

... and 11 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f601912...005e441. Read the comment docs.

Files Changed Coverage Δ
server/broadcast.go 77.46835% <100.00000%> (-0.08941%) ⬇️

... and 11 files with indirect coverage changes

@cyberj0g
Copy link
Contributor

cyberj0g commented Jan 23, 2023

@mjh1 thanks for looking into that.
I had a slightly more generic solution in mind, like, a wrapper to add more detailed error message along with custom error type, without masking the root error:

ErrFancyCustomError  = errors.New("custom message")
...
func faulty() error {
    err = ...
    return fmt.Errorf("even more detailed message: %w", lperrors.Error(ErrFancyCustomError, err))
    // with a pre-defined message and error type, but root cause error is also included
    // return lperrors.Error(ErrFancyCustomError, err)
}
...
anErr = faulty()
if errors.Is(anErr, ErrFancyCustomError) {
// true
}
// anErr printed like this:
// custom message: even more detailed message: context cancelled

Also, I think it's not a good idea to use errors as a package name, because there's a builtin package with the same name. Maybe I'm inventing the wheel here, let me know what you think.

PS: it's not a high priority feature

@mjh1
Copy link
Contributor Author

mjh1 commented Jan 23, 2023

@cyberj0g yeah I was trying to figure out a way to make it generic, it's a little fiddly but I think my latest change should be good enough. It'll get a lot easier in go 1.20 we'll be able wrap multiple errors: https://tip.golang.org/doc/go1.20#errors

@cyberj0g
Copy link
Contributor

cyberj0g commented Jan 23, 2023

https://tip.golang.org/doc/go1.20#errors

Cool! Maybe we could just backport some functions we are interested in, such as: errrors.Is, fmt.Errorf from 1.20 to a lperrors package, and then delete that, once we move go-livepeer to Go 1.20? These functions are few lines usually, it shouldn't be too hard.

@mjh1
Copy link
Contributor Author

mjh1 commented Jan 23, 2023

ah good plan 👍

@mjh1
Copy link
Contributor Author

mjh1 commented Jan 25, 2023

@cyberj0g annoyingly i'm not sure it's possible, the Is function makes use of this internal reflection package: https://github.com/golang/go/blob/go1.20rc3/src/errors/wrap.go#L8
what do you think?

@cyberj0g
Copy link
Contributor

Ok, let's draft that until Go 1.20 is released. Thanks for researching!

@mjh1 mjh1 marked this pull request as draft February 3, 2023 11:34
@mjh1 mjh1 removed the request for review from cyberj0g February 3, 2023 11:34
@mjh1 mjh1 marked this pull request as ready for review September 5, 2023 10:44
Copy link
Contributor

@thomshutt thomshutt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful

@mjh1 mjh1 merged commit 30dcc8a into master Sep 13, 2023
15 checks passed
@mjh1 mjh1 deleted the mh/err-type branch September 13, 2023 08:25
eliteprox pushed a commit to eliteprox/go-livepeer that referenced this pull request Feb 21, 2024
* Use a custom error type instead of string matching

* changelog

---------

Co-authored-by: Thom Shutt <thomshutt@users.noreply.github.com>
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