This repository was archived by the owner on Nov 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Some errors with --fix that can silently break code logicΒ #108
Copy link
Copy link
Open
Description
Here is a piece of code
package foo
import (
"encoding/xml"
"strings"
)
func _(xmlInput string) {
d := xml.NewDecoder(strings.NewReader(xmlInput))
var tag struct {
Whatever string `xml:"whatever"`
}
err := d.Decode(&tag)
if err != nil {
if syntaxErr, ok := err.(*xml.SyntaxError); ok && syntaxErr.Msg != "unexpected EOF" {
panic("unexpected XML syntax error")
}
}
}The logic of the code is crappy, that's not the point π
Here is what errorlint suggests:
type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)
if syntaxErr, ok := err.(*xml.SyntaxError); ok && syntaxErr.Msg != "unexpected EOF" {
And it's OK
What is not is what the code is replaced when using --fix
package foo
import (
"encoding/xml"
"errors"
"strings"
)
func _(xmlInput string) {
d := xml.NewDecoder(strings.NewReader(xmlInput))
var tag struct {
Whatever string `xml:"whatever"`
}
err := d.Decode(&tag)
if err != nil {
syntaxErr := &xml.SyntaxError{}
if errors.As(err, &syntaxErr) {
panic("unexpected XML syntax error")
}
}
}The error.As is OK but a part of the test is nuked: && syntaxErr.Msg != "unexpected EOF" disappeared
I'm using buildID=0464206b09fb150f31313cdecad2010b30c95d892df7844ab7b297caea930e30
kakkoyun
Metadata
Metadata
Assignees
Labels
No labels