Doesn't handle bad recover usage
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 2.5k
- Forks
- 102
- PR merge metrics
- No merged PRs in 30d
Description
I was doing something dumb. I figured defer recover() would work. Turns out it doesn't. Thankfully, godebug helped me discover this. Because it exploded when it tried to instrument that statement. Maybe add a check and error out saying, "Yo, you're being an idiot. This doesn't work like that." Instead of exploding. Just a thought.
$ godebug build -instrument=my/pkg/path -o out.exe
panic: reflect.Set: value of type *ast.UnaryExpr is not assignable to type *ast.CallExpr
goroutine 1 [running]:
panic(0x6f0200, 0xc085b6b070)
C:/Tools/Go/src/runtime/panic.go:464 +0x3f4
reflect.Value.assignTo(0x79d2c0, 0xc08737f2e0, 0x16, 0x802440, 0xb, 0x79aac0, 0x0, 0x0, 0x0, 0x0)
C:/Tools/Go/src/reflect/value.go:2164 +0x3c5
reflect.Value.Set(0x79aac0, 0xc08210e228, 0x196, 0x79d2c0, 0xc08737f2e0, 0x16)
C:/Tools/Go/src/reflect/value.go:1334 +0x9c
github.com/mailgun/godebug/gen.rewriteRecoverCall(0x2993450, 0xc08210e220, 0x2992bd8, 0xc0820ed880)
C:/Source/Go/src/github.com/mailgun/godebug/gen/gen.go:1044 +0x3e4
github.com/mailgun/godebug/gen.(*recoverVisitor).Visit(0xc08737f240, 0x2992bd8, 0xc0820ed880, 0x0, 0x0)
C:/Source/Go/src/github.com/mailgun/godebug/gen/gen.go:1026 +0x223
go/ast.Walk(0x29934d0, 0xc08737f240, 0x2992bd8, 0xc0820ed880)
C:/Tools/Go/src/go/ast/walk.go:52 +0x5d
go/ast.Walk(0x29934d0, 0xc08737f240, 0x2993450, 0xc08210e220)
C:/Tools/Go/src/go/ast/walk.go:213 +0x4194
go/ast.walkStmtList(0x29934d0, 0xc08737f220, 0xc082105fc0, 0x2, 0x2)
C:/Tools/Go/src/go/ast/walk.go:32 +0xdc
go/ast.Walk(0x29934d0, 0xc08737f220, 0x2905ac0, 0xc0820e7a10)
C:/Tools/Go/src/go/ast/walk.go:224 +0x3e25
go/ast.Walk(0x29934d0, 0xc08737f1c0, 0x2905a90, 0xc0820ed900)
C:/Tools/Go/src/go/ast/walk.go:231 +0x4054
go/ast.walkStmtList(0x29934d0, 0xc08737efe0, 0xc082110020, 0x2, 0x2)
C:/Tools/Go/src/go/ast/walk.go:32 +0xdc
go/ast.Walk(0x29934d0, 0xc08737efe0, 0x2905ac0, 0xc0820e7aa0)
C:/Tools/Go/src/go/ast/walk.go:224 +0x3e25
github.com/mailgun/godebug/gen.rewriteRecoversIn(0xc0820e7aa0, 0x2)
C:/Source/Go/src/github.com/mailgun/godebug/gen/gen.go:1013 +0x10d
github.com/mailgun/godebug/gen.(*visitor).Visit(0xc0872fe620, 0x2992c38, 0xc08210e2b0, 0x0, 0x0)
C:/Source/Go/src/github.com/mailgun/godebug/gen/gen.go:606 +0x3784
go/ast.Walk(0x29934a8, 0xc0872fe620, 0x2992c38, 0xc08210e2b0)
C:/Tools/Go/src/go/ast/walk.go:52 +0x5d
go/ast.Walk(0x29934a8, 0xc0872fe620, 0x2992bd8, 0xc0820ed940)
C:/Tools/Go/src/go/ast/walk.go:136 +0x1d85
go/ast.Walk(0x29934a8, 0xc0872fe5b0, 0x2993218, 0xc08210e2d0)
C:/Tools/Go/src/go/ast/walk.go:210 +0x162f
go/ast.walkStmtList(0x29934a8, 0xc08737d420, 0xc08206f280, 0x8, 0x8)
C:/Tools/Go/src/go/ast/walk.go:32 +0xdc
go/ast.Walk(0x29934a8, 0xc08737d420, 0x2905ac0, 0xc0820e7ad0)
C:/Tools/Go/src/go/ast/walk.go:224 +0x3e25
go/ast.Walk(0x29934a8, 0xc08737c310, 0x2992de8, 0xc0820e7b00)
C:/Tools/Go/src/go/ast/walk.go:344 +0xb4d
go/ast.walkDeclList(0x29934a8, 0xc088889180, 0xc082070b00, 0xa, 0x10)
C:/Tools/Go/src/go/ast/walk.go:38 +0xdc
go/ast.Walk(0x29934a8, 0xc088889180, 0x2a44800, 0xc08206f380)
C:/Tools/Go/src/go/ast/walk.go:353 +0x29c0
github.com/mailgun/godebug/gen.Generate(0xc0820095c0, 0x893570, 0xc089d2bbd0)
C:/Source/Go/src/github.com/mailgun/godebug/gen/gen.go:70 +0x9e4
main.generateSourceFiles(0xc08200d040, 0x7f4858, 0x5, 0x0, 0x0)
C:/Source/Go/src/github.com/mailgun/godebug/cmd.go:404 +0x56c
main.doBuild(0xc082012200, 0x3, 0x3)
C:/Source/Go/src/github.com/mailgun/godebug/cmd.go:212 +0x226
main.main()
C:/Source/Go/src/github.com/mailgun/godebug/cmd.go:175 +0x35b
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in gen/gen.go at rewriteRecoverCall and recoverVisitor.Visit, which appear in the reported stack trace. Reproduce the failure with godebug build -instrument=my/pkg/path -o out.exe on code containing defer recover(), then verify the command reports a clear error instead of panicking.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100