Skip to content

Conversation

@adamziel
Copy link
Collaborator

@adamziel adamziel commented Jul 23, 2025

Motivation for the change, related issues

The new Comlink error handler rewired the logic around passing errors from web workers to the Playground web app. Specifically, it enriched the error with additional stack trace before rethrowing it:

throw new Error('Comlink method call failed', {
	cause: originalError
});

Unfortunately, this also put the original error at the bottom of the error.cause chain, making error handling confusing for the API consumers.

This PR ensures the thrown error the original one. This way a simple try {} catch(e) {} is enough to log the error details without having to reason about e.cause.cause etc. The additional stack trace information is now attached at the bottom of the cause chain for when the developer needs to inspect it.

Testing Instructions (or ideally a Blueprint)

Run Playground with this Blueprint and confirm the top-level error message speaks about PHP failure. Specifically, it should not say "Comlink method call failed":

{
  "steps": [
    {
      "step": "mkdir",
      "path": "/wordpress/wp-content/mu-plugins"
    },
    {
      "step": "writeFile",
      "path": "/wordpress/wp-content/mu-plugins/test.php",
      "data": "<?php undefined_function();"
    }
  ]
}

@adamziel adamziel merged commit 083a1e2 into trunk Jul 23, 2025
22 of 24 checks passed
@adamziel adamziel deleted the comlink-attach-more-stack-at-the-end-of-the-error-chain branch July 23, 2025 21:28
@brandonpayton
Copy link
Member

Thanks for this, @adamziel!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants