Skip to content

Avoid errors due to log message formatting - #1726

Merged
brandonpayton merged 1 commit into
trunkfrom
fix-logger-message-prop-error
Sep 3, 2024
Merged

Avoid errors due to log message formatting#1726
brandonpayton merged 1 commit into
trunkfrom
fix-logger-message-prop-error

Conversation

@brandonpayton

Copy link
Copy Markdown
Member

Motivation for the change, related issues

Today, we attempt to reassign an error's message property for formatting purposes, but this throws an exception if the error property isn't writable or doesn't have a setter. For example:

TypeError: Cannot set property message of #<ErrorEvent2> which has only a getter

These are the assignments that occasionally lead to the error:
https://github.com/WordPress/wordpress-playground/blob/trunk/packages/php-wasm/logger/src/lib/handlers/log-to-console.ts#L9-L11

Since the assignments are just for formatting, it should be OK if we just tolerate the failed assignment using Reflect.set().

Fixes #1514

Implementation details

Use Reflect.set() to avoid exceptions when the assignment fails.

Testing Instructions (or ideally a Blueprint)

  • CI
  • Tested manually by causing errors in the PHP runtime
@brandonpayton brandonpayton self-assigned this Sep 3, 2024
@brandonpayton brandonpayton added [Type] Bug An existing feature does not function as intended [Package][@php-wasm] Logger labels Sep 3, 2024
@brandonpayton
brandonpayton force-pushed the fix-logger-message-prop-error branch from 96de945 to 601ed46 Compare September 3, 2024 20:05
@brandonpayton
brandonpayton requested a review from a team September 3, 2024 20:27
@brandonpayton
brandonpayton merged commit af6e1de into trunk Sep 3, 2024
@brandonpayton
brandonpayton deleted the fix-logger-message-prop-error branch September 3, 2024 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package][@php-wasm] Logger [Type] Bug An existing feature does not function as intended

1 participant