Skip to content
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

De-duplication logic causes some sentinel error patterns to result in error chain losses #41

Closed
Southclaws opened this issue Oct 23, 2023 · 0 comments

Comments

@Southclaws
Copy link
Owner

Southclaws commented Oct 23, 2023

fault/flatten.go

Lines 73 to 79 in 84c038e

// de-duplicate nested error messages
if next != nil {
if idx := strings.Index(message, next.Error()); idx != -1 {
// cut off the duplicate message and remove the separator.
message = strings.Trim(message[:idx], ": ")
}
}

Repro:

ErrPost = errors.New("post")

ErrExampleOne = fmt.Errorf("%w: %s", ErrPost, "example one")
ErrExampleTwo = fmt.Errorf("%w: %s", ErrExampleOne, "example two")

Expected chain:

post: example one: example two

What actually happens:

post

This one-word error message pattern seems to pop up sometimes, it's even in the standard library so it's definitely worth supporting.

Essentially what happens, I think, is that fmt.Errorf when used this way results in a single error with two messages nested within it:

ErrPost = "post"
ErrExampleOne = "post: example one"
ErrExampleTwo = "post: example one: example two"

So when you chain these together, you get a lot of duplication:

post: post: example one: post: example one: example two

Or, flattened:

"post"
"post: example one"
"post: example one: example two"

So when the de-duplication logic runs over this, it strips the 2 succeeding error messages because they begin with the first 4 bytes as the what the current iteration points to.

Which I guess is fine, as the actual chained error is mostly useless anyway, the Flatten output is what matters.

What I'd ideally want out of this is:

"post"
"example one"
"example two"

But, rolling all of these into one error will probably be simpler for now instead of trying to unwrap error messages into error chains where errors never existed. Otherwise you end up with:

"post"
"post"
"example one"
"post"
"example one"
"example two"
Southclaws added a commit that referenced this issue Nov 21, 2023
…t in error chain losses #41

Also removed some tests instead of painstakingly updating as I need to rewrite them anyway...
Southclaws added a commit that referenced this issue Nov 21, 2023
…t in error chain losses #41

Also removed some tests instead of painstakingly updating as I need to rewrite them anyway...
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

No branches or pull requests

1 participant