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

mime/multipart: wrong error wrapping in multipart.go on L346? #54133

Closed
pH-T opened this issue Jul 29, 2022 · 6 comments
Closed

mime/multipart: wrong error wrapping in multipart.go on L346? #54133

pH-T opened this issue Jul 29, 2022 · 6 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@pH-T
Copy link

pH-T commented Jul 29, 2022

What version of Go are you using (go version)?

go1.18.3 linux/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

tried to catch errors with errors.Is(err, io.EOF) from multipart.NewReader(...)..NextPart()

What did you expect to see?

expected to catch io.EOF errors, but it seems to only work if we enter the if in L337 - io.EOF is directly returned.

What did you see instead?

multipart: NextPart: EOF --> wrongly (?) wrapped error

changing%v to %w in L346 fixed this issue - so most likely a bug?

@cherrymui
Copy link
Member

Do you have a code example that doesn't work as expected? Thanks.

@cherrymui cherrymui added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 29, 2022
@odeke-em odeke-em changed the title affected/package: mime/multipart/multipart.go - wrong error wrapping in L346 ? mime/multipart: wrong error wrapping in multipart.go on L346? Jul 30, 2022
@pH-T
Copy link
Author

pH-T commented Jul 30, 2022

hi @cherrymui,
thanks for your fast response!

here is a code example: https://go.dev/play/p/BfjeTIOkq-M

@seankhliao
Copy link
Member

From the definition of io.EOF:

Functions should return EOF only to signal a graceful end of input. If the EOF occurs unexpectedly in a structured data stream, the appropriate error is either ErrUnexpectedEOF or some other error giving more detail.

This is an unexpected end of input, so the error is correct.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jul 30, 2022
@pH-T
Copy link
Author

pH-T commented Jul 30, 2022

hi @seankhliao,
indeed the error itself is correct - I never said something different!
Im pretty sure that the "wrapping" in L346 is wrong! By returning the io.EOF with "%v" it is not wrapped and thus not useable with errors.Is().
By replaceing the "%v" with a "%w" it works as expected...
So its not about the error itself!

@seankhliao
Copy link
Member

but allowing you to test against EOF is wrong, since EOF represents a clean exit, and this is not

@pH-T
Copy link
Author

pH-T commented Jul 30, 2022

hi @seankhliao,
the following code is used in mime/multipart/multipart.go#L346:

...
		if err != nil {
			return nil, fmt.Errorf("multipart: NextPart: %v", err)
		}
...

by using "%v" the caller can not check the error and it does not have to be an io.EOF error - it could be any error...
so the caller just sees the error but is not able to check what kind of error it is!

further I do not understand what you mean by "but allowing you to test against EOF is wrong, since EOF represents a clean exit, and this is not" - you should be allowed to test against any error (error wrapping - https://pkg.go.dev/errors) but thats a different topic...

@golang golang locked and limited conversation to collaborators Jul 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants