-
Notifications
You must be signed in to change notification settings - Fork 1
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
Improve error handling #116
base: main
Are you sure you want to change the base?
Conversation
Go coverage report: Click to expand.
Go lint report: No issues found. 😎 |
This will be great, thank you for working on this. Two thoughts: I wonder how cautious we should be about not breaking the public interface in terms of errors returned. The current defined errors (like Any reason why you decided to not go with carbonapi/zipper/types/errors.go Lines 13 to 34 in 02613ff
Extra info could be added like this: var BadType = merry.New("bad type")
err := BadType.Append("expected string - got int")
fmt.Println(err.Error()) // bad type: expected string - got int I see that the errors in the parser are defined with carbonapi/pkg/parser/interface.go Lines 32 to 49 in 02613ff
but it looks like that's ~5 years old, and merry was introduced later. So I think it's OK to migrate those errors to merry |
I believe most of the errors I have added were were defined with fmt.Errorf() or error.New(), so they weren't originally defined as merry errors. One thing we could do is define any errors that were originally created with merry.New() as merry errors. What we could also do is merry.Wrap() with these new error types, which will make them into merry errors. |
func (e ErrMissingExpr) HTTPStatusCode() int { | ||
return http.StatusBadRequest | ||
} |
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 can't think of any errors we would define here that are not bad requests, plus I don't see we are using this method anywhere yet. So I believe we can don't define these for now to simplify the code if you agree
Exp string | ||
Got string |
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.
Idea: maybe these could be of type ExprType
and the func (e ErrBadType) Error()
could take care of formatting them? (i.e. EtName
-> "series name"
, EtBool
-> "bool"
, etc)
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.
In some cases, more than one type is acceptable, i.e. EtConst or EtString. What should we do in that case?
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.
Maybe I can make Expected a list of type ExprType, then join them?
pkg/errors/errors.go
Outdated
type ErrInvalidArgument string | ||
|
||
func (e ErrInvalidArgument) Error() string { | ||
return fmt.Sprintf("\"too many arguments\" %q", string(e)) |
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.
Probably left from copypaste
This commit adds the files that are specific to Grafana's fork that are not intended to be included in the upstream. This files are already present in the commit history (they were deleted), but this is an attempt of a fresh start on top of the upstream's `main`. At the moment, this should the only commit we expect to skip when sending our changes.
27e9a61
to
e1f83cd
Compare
* Fix exponentialMovingAverage panic The panic was happening when the window size was greater than the length of the values. Now if that happens no panics occur and the average is returned. This matches graphiteweb. * Add support for Graphite web toLowerCase function * Add tests for toLowerCase function * Update glue.go * Update COMPATIBILITY.md to show support of toLowerCase * Add support for Graphite web toUpperCase function * Add tests for toUpperCase function * Update glue.go * Update COMPATIBILITY.md to include toUpperCase function * Add support for Graphite web sumSeriesLists function * Add tests for sumSeriesLists * Update glue.go * Update COMPATIBILITY.md to include sumSeriesLists * Fix problems that I accidentally introduced while trying to resolve merge conflict * Another attempt to fix previous problem Apparantly there is a directory that gen.go wasn't expecting and `go generate` in expr/functions produced `glue.go` file that didn't compile fix both generator and glue * Adds Drone and Github workflow for Grafana's fork This commit adds the files that are specific to Grafana's fork that are not intended to be included in the upstream. This files are already present in the commit history (they were deleted), but this is an attempt of a fresh start on top of the upstream's `main`. At the moment, this should the only commit we expect to skip when sending our changes. Co-authored-by: Nicolás Pazos <npazosmendez@gmail.com> Co-authored-by: Vladimir Smirnov <civiloid@google.com>
e683b99
to
f81cb69
Compare
This PR creates an error package that can be reused throughout the code and will provide better detail regarding the origin of the error. This is useful for testing errors.