Skip to content

Don't let an unserializable Allure attachment abort the whole test run (#902) - #928

Open
thai2301 wants to merge 1 commit into
magento:developfrom
thai2301:902-allure-serialization-closure-crash
Open

Don't let an unserializable Allure attachment abort the whole test run (#902)#928
thai2301 wants to merge 1 commit into
magento:developfrom
thai2301:902-allure-serialization-closure-crash

Conversation

@thai2301

Copy link
Copy Markdown

Description

AllureHelper::addAttachmentToCurrentStep() catches the Exception that serialize() throws when the given data contains a Closure, then re-throws using $data->getMessage() instead of the caught $exception. $data at that point is still the original, unserialized value (in the reported case, a \Throwable being attached to the report), so this either surfaces a misleading message or, for values with no getMessage() method, throws a new, unhandled error — which aborts the entire test run instead of just the one test that failed.

addAttachmentToLastStep() has the identical serialize() call with no exception handling at all, so it fails the same way for the same root cause.

This matches the reported symptom exactly: a single failing test's own exception gets attached to Allure via TestContextExtension::attachExceptionToAllure()AllureHelper::addAttachmentToCurrentStep($exception, ...). If that exception's object graph contains a bound Closure anywhere in its trace, serialize() fails, and the broken re-throw takes down the whole suite instead of letting the next test run.

Fix

Both methods now fall back to a descriptive placeholder string (Unable to serialize attachment data of type "...": <original message>) when serialize() fails, instead of ever re-throwing. A debugging attachment that can't be losslessly serialized should not be able to take the rest of the test run down with it.

Fixed Issues (if relevant)

  1. Serialization of 'Closure' is not allowed #902: Serialization of 'Closure' is not allowed

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/verification tests (if applicable)
  • All automated tests passed successfully (all builds are green)
  • Changes to Framework doesn't have backward incompatible changes for tests or have related Pull Request with fixes to tests

AllureHelper::addAttachmentToCurrentStep() caught the exception serialize()
throws for values containing a Closure, then re-threw using $data->getMessage()
instead of the caught $exception. Since $data at that point is still the
original, unserialized value, this either surfaces the wrong message or,
when $data has no getMessage() method, throws a new, unhandled error that
aborts the entire suite instead of the single failing test.

addAttachmentToLastStep() had the identical serialize() call with no
exception handling at all, so it failed the same way.

Both now fall back to a descriptive placeholder string when serialization
fails, so a debugging attachment that can't be losslessly serialized no
longer takes the rest of the test run down with it.
@thai2301

Copy link
Copy Markdown
Author

@magento run all tests

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