-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: Add Design.md to explain refactor #15
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
base: main
Are you sure you want to change the base?
Conversation
DESIGN.md
Outdated
| * WithDetail: provide a message that details the error | ||
| * WithProperty: provide a key/value pair for additional informations (filename, path, username, ... ) | ||
| * WithIdentifier: used to provide an identifer, it could be concatenated with other idenfier from previous calls from subfunctions (See example below for clarity) |
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 would put the With<Name> in verbatim style
DESIGN.md
Outdated
| Signature could be as follow | ||
|
|
||
| ```go | ||
| errors.WithIdentifier(int): |
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 let an ending semicolon there
DESIGN.md
Outdated
| ```go | ||
| errors.WithIdentifier(int): | ||
| errors.WithDetail(string) | ||
| errors.WithDetailf(string, ...any) |
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.
an extra space is here
DESIGN.md
Outdated
| * WithDetail: provide a message that details the error | ||
| * WithProperty: provide a key/value pair for additional informations (filename, path, username, ... ) | ||
| * WithIdentifier: used to provide an identifer, it could be concatenated with other idenfier from previous calls from subfunctions (See example below for clarity) | ||
|
|
||
| Signature could be as follow | ||
|
|
||
| ```go | ||
| errors.WithIdentifier(int): | ||
| errors.WithDetail(string) | ||
| errors.WithDetailf(string, ...any) | ||
| errors.WithProperty(string, any) | ||
| ``` |
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 would put them in the same order
DESIGN.md
Outdated
| ``` | ||
| forbidden (19-12-2): permission denied: missing required role: File='test.txt', User='john.doe', Role:'Reader', at=(func='main.appel3', file='main.go', line='270') | ||
| ``` | ||
|
|
||
| ```go | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| errors "github.com/scality/go-errors" | ||
| ) | ||
|
|
||
| var ErrForbidden = errors.New("forbidden") | ||
|
|
||
| func main(){ | ||
| err := appel1() | ||
| fmt.Println(err) | ||
| } | ||
| func appel1() error { | ||
| return errors.Wrap( | ||
| appel2(), | ||
| errors.WithIdentifier(19), | ||
| ) | ||
| } | ||
|
|
||
| func appel2() error { | ||
| return errors.Wrap( | ||
| appel3(), | ||
| errors.WithDetail("missing required role"), | ||
| errors.WithProperty("Role", "Reader"), | ||
| errors.WithProperty("User", "john.doe"), | ||
| errors.WithIdentifier(12), | ||
| ) | ||
| } | ||
|
|
||
| func appel3() error { | ||
| // Something went wrong here | ||
| return errors.Wrap( | ||
| ErrForbidden, | ||
| errors.WithIdentifer(2), | ||
| errors.WithDetail("permission denied"), | ||
| errors.WithProperty("File", "test.txt"), | ||
| ) | ||
| } | ||
| ``` |
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.
To me, I think it's better to put the error result after the code.
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.
also missing a new line between main and appel1
Also also, I would rename appelX by funcX or foo bar baz, etc.
Signed-off-by: Anthony TREUILLIER <anthony.treuillier@scality.com>
68a4669 to
25d6c21
Compare
No description provided.