refactor: Add Design.md to explain refactor#15
Open
anthony-treuillier-scality wants to merge 1 commit intomainfrom
Open
refactor: Add Design.md to explain refactor#15anthony-treuillier-scality wants to merge 1 commit intomainfrom
anthony-treuillier-scality wants to merge 1 commit intomainfrom
Conversation
DESIGN.md
Outdated
Comment on lines
28
to
30
| * 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.
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.
You let an ending semicolon there
DESIGN.md
Outdated
| ```go | ||
| errors.WithIdentifier(int): | ||
| errors.WithDetail(string) | ||
| errors.WithDetailf(string, ...any) |
DESIGN.md
Outdated
Comment on lines
28
to
39
| * 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.
I would put them in the same order
DESIGN.md
Outdated
Comment on lines
44
to
89
| ``` | ||
| 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.
To me, I think it's better to put the error result after the code.
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.