Skip to content

Fail handler reports incorrect line numbers #443

@marcogschmidt

Description

@marcogschmidt

We need to account for the extra function in the call stack when registering a custom fail handler, otherwise the line numbers that are reported on failures are incorrect, e.g.:
image

The solution is this:

RegisterFailHandler(func(message string, callerSkip ...int) {
		// Your custom logic here...// Account for this extra function in the call stack.
		// Without this all failure messages will show the incorrect line number!
		var shiftedCallerSkip []int
		for _, i := range callerSkip {
			shiftedCallerSkip = append(shiftedCallerSkip, i+1)
		}
​
		Fail(message, shiftedCallerSkip...)
	})

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions