refactor: Add Design.md to explain refactor#15
refactor: Add Design.md to explain refactor#15anthony-treuillier-scality wants to merge 1 commit intomainfrom
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.
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
| * 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
| ``` | ||
| 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.
68a4669 to
25d6c21
Compare
DESIGN.md
Outdated
| err := appel1() | ||
| fmt.Println(err) | ||
| } | ||
| func appel1() error { | ||
| return errors.Wrap( | ||
| appel2(), |
| # Variadic Options | ||
| The variadic options would be the following one | ||
|
|
||
| * `WithDetail`/`WithDetailf`: 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.
at the risk of being redundant I would like to ask about the naming of these options,
using the keyword "with" I would expect something like:
something.WithSomethingElse(.....)
is there a reason we don't call these options just Detail,Property, ...
func appel1() error {
return errors.Wrap(
appel2(),
errors.Identifier(19),
)
}There was a problem hiding this comment.
This is just a common pattern among some broadly used library, that I personnaly like a lot
There was a problem hiding this comment.
small comment otherwise I completely agree with this design.
keeping the Identifiers vague as a responsibility to the user is a good touch.
do we plan on having helper functions for this library to ease error parsing ?
for example HasIdentifier, HasProperty, GetProperty
are properties guaranteed to be unique ?
thanks @anthony-treuillier-scality 👍🏼
DESIGN.md
Outdated
| @@ -0,0 +1,92 @@ | |||
| Design for go-errors refactor | |||
There was a problem hiding this comment.
Nit: To me it's weird to have this line here
There was a problem hiding this comment.
We can consider it as a title, but I will remove it
DESIGN.md
Outdated
| Design for go-errors refactor | ||
|
|
||
| # Introduction | ||
| The main objective of this refactor is to ease the usage of go-errors library, with key points |
There was a problem hiding this comment.
I would prefer we describe the "final view" of the lib and not talk about refactor here (so that it can be read at any time once it's merged)
There was a problem hiding this comment.
ok
There was a problem hiding this comment.
but i am just talking about refactor
69670bf to
fe83fa3
Compare
Signed-off-by: Anthony TREUILLIER <anthony.treuillier@scality.com>
fe83fa3 to
0c5125a
Compare
No description provided.