Skip to content

fix: report the correct caller in assert panics#1155

Open
immanuwell wants to merge 1 commit into
envoyproxy:mainfrom
immanuwell:fix/assert-caller-location
Open

fix: report the correct caller in assert panics#1155
immanuwell wants to merge 1 commit into
envoyproxy:mainfrom
immanuwell:fix/assert-caller-location

Conversation

@immanuwell

Copy link
Copy Markdown
Contributor

small fix, but this panic output was kinda lying.
assert.Assert(false) could report the outer frame instead of the real caller, so debugging was a bit meh.

Related: #1007

What changed

  • switch src/assert.Assert to runtime.CallersFrames
  • add a regression test for the reported file/function

Repro

  1. create /tmp/assert_repro.go:
package main

import "github.com/envoyproxy/ratelimit/src/assert"

func fail() { assert.Assert(false) }
func main() { fail() }
  1. run go run /tmp/assert_repro.go
  2. before this change the panic points at main.main
  3. after this change it points at main.fail, which is the real call site

Checks

  • go test ./src/assert
  • go test ./...

Signed-off-by: immanuwell <pchpr.00@list.ru>
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.

1 participant