Skip to content

refactor: Add Design.md to explain refactor#15

Open
anthony-treuillier-scality wants to merge 1 commit intomainfrom
improvement/refactor
Open

refactor: Add Design.md to explain refactor#15
anthony-treuillier-scality wants to merge 1 commit intomainfrom
improvement/refactor

Conversation

@anthony-treuillier-scality
Copy link
Contributor

No description provided.

@anthony-treuillier-scality anthony-treuillier-scality requested a review from a team as a code owner December 10, 2025 08:48
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)

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):

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)

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
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)
```

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
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"),
)
}
```

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.

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.

DESIGN.md Outdated
Comment on lines +58 to +63
err := appel1()
fmt.Println(err)
}
func appel1() error {
return errors.Wrap(
appel2(),
Copy link

Choose a reason for hiding this comment

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

call instead of appel 👍

Comment on lines +25 to +30
# 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)
Copy link

Choose a reason for hiding this comment

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

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),
    )
}

Copy link

Choose a reason for hiding this comment

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

This is just a common pattern among some broadly used library, that I personnaly like a lot

Copy link

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

Nit: To me it's weird to have this line here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but i am just talking about refactor

@anthony-treuillier-scality anthony-treuillier-scality force-pushed the improvement/refactor branch 2 times, most recently from 69670bf to fe83fa3 Compare March 5, 2026 05:51
Signed-off-by: Anthony TREUILLIER <anthony.treuillier@scality.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.

5 participants