Skip to content

Conversation

@adamziel
Copy link
Collaborator

@adamziel adamziel commented Jul 13, 2025

Motivation for the change, related issues

Cleans up the data flows for logging errors. Before this PR, some things would be always logged, other errors would be emitted as events, and others thrown. With this PR, errors are thrown and propagated to the caller – even across the Comlink boundary. This PR introduces an enhanced error serializer/unserializer that preserves the cause and custom properties (e.g. error.status).

Improved the logging surfaced a few tactical problems, so this PR also changes a few nuances here and there, e.g. how PHPProcessManager.spawn() ensures the primary instance isn't acquired twice, or that createNodeFsMountHandler returns a synchronous, not async function.

Related to #2298

Testing Instructions (or ideally a Blueprint)

Confirm all the unit tests still pass

@adamziel adamziel marked this pull request as ready for review July 14, 2025 09:46
@adamziel adamziel merged commit 0d24461 into trunk Jul 14, 2025
67 of 75 checks passed
@adamziel adamziel deleted the improve-error-handling branch July 14, 2025 09:46
adamziel added a commit that referenced this pull request Jul 23, 2025
## Motivation for the change, related issues

The [new Comlink error
handler](#2357)
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:

```js
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":

```json
{
  "steps": [
    {
      "step": "mkdir",
      "path": "/wordpress/wp-content/mu-plugins"
    },
    {
      "step": "writeFile",
      "path": "/wordpress/wp-content/mu-plugins/test.php",
      "data": "<?php undefined_function();"
    }
  ]
}
```
adamziel added a commit that referenced this pull request Jul 25, 2025
…rors (#2429)

## Motivation for the change, related issues

The [recent
PR](#2357), that
altered how error reporting works, unintentionally removed the
`request.error` event in some PHP.run() code paths. This PR makes sure
the `request.error` event is emitted anytime a non-zero-exit error
happens.

## Testing Instructions (or ideally a Blueprint)

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants