Skip to content

Conversation

olivergondza
Copy link
Contributor

Summary

Always report error message on PanicsWithError error message mismatch.

Changes

Add Error message field to the failure message, that reports panicErr.Error() IFF it panicked with an error its message is different from expected.

Motivation

Better defect localization in case of nested errors causing panic.

Before:

Error: func (assert.PanicTestFunc)(0x627a80) should panic with error message:	"at the disco"
	Panic value:	&errors.joinError{errs:[]error{(*errors.errorString)(0xc0000a1540), (*errors.errorString)(0xc0000a1550)}}
	Panic stack:	goroutine 19 [running]:
	...

After:

Error: func (assert.PanicTestFunc)(0x627b20) should panic with error message:	"at the disco"
	Panic value:	&errors.joinError{errs:[]error{(*errors.errorString)(0xc000065550), (*errors.errorString)(0xc000065560)}}
	Error message:	"wrapped err msg\nother err msg"
	Panic stack:	goroutine 6 [running]:
	...

Related issues

Closes #1399

@dolmen dolmen added pkg-assert Change related to package testify/assert enhancement labels Jul 6, 2023
@dolmen dolmen added the enhancement: output format Enhancement related to formatting of messages label Jun 2, 2025
Copy link
Collaborator

@dolmen dolmen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests must be fixed to not use assert.CollectT.

@dolmen dolmen changed the title Fix #1399: Always report error message on PanicsWithError mismatch assert.PanicsWithError: report error message Jun 2, 2025
@olivergondza
Copy link
Contributor Author

@dolmen, I have performed the needed refactor and rebased. PTAL.

The captureTestingT could not have been used in the most straightforward way possible, as some of the checks are negative, and test other "labels" than error...

dolmen
dolmen previously requested changes Jun 2, 2025
brackendawson
brackendawson previously approved these changes Aug 26, 2025
Copy link
Collaborator

@brackendawson brackendawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this myself and it works, the change is a worthwhile improvement.

@dolmen are you happy that your comments are addressed?

Copy link
Collaborator

@brackendawson brackendawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM

@brackendawson brackendawson dismissed dolmen’s stale review September 10, 2025 06:52

dolmen's last change requested, to change the variable name mckT to mockT, was completed.

@brackendawson brackendawson merged commit b5a0821 into stretchr:master Sep 10, 2025
9 checks passed
@olivergondza olivergondza deleted the issue-1399 branch September 10, 2025 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement: output format Enhancement related to formatting of messages enhancement help wanted must-rebase pkg-assert Change related to package testify/assert

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PanicsWithError does not report error message for complex errors

4 participants