Skip to content

Commit

Permalink
Blueprints: Throw on failure (#982)
Browse files Browse the repository at this point in the history
Ensures the Blueprint steps throw an error on failure. For now, the
error is merely reported in the console. In the future, there may be a
nice UI for this.

This PR is an addition to
#605 as it
prepares the Blueprint steps for the changes in the Blueprint
compilation engine.

Detecting a runPHP failure required adjusting the php_wasm.c code to
return the correct exit code. The previous method of inferring the exit
code was replaced by simply returning `EG(exit_status)` which is
populated by the zend engine.

Furthermore, this PR ships additional unit tests for some Blueprint
steps to ensure they indeed throw as expected.

## Changes description

### `throwOnError` option

`BasePHP.run()` now accepts a `throwOnError` option that throws an error
whenever PHP returns an exit code different than `0`:

```js
// This will throw a JavaScript exception 
await php.run({
	throwOnError: true,
	code: '<?php no_such_function()'
});
```

This happens in the following cases:

 * syntax error
 * undefined function call
 * fatal error
 * calling `exit(1)`
 * uncaught PHP exception
 * ...probably some more

This option is set to `true` by all the Blueprint steps.

## Remaining work

- [x] Rebuild all the PHP.wasm versions

## Testing instructions

This PR comes with test coverage so confirm all the tests pass in CI.

Also, apply this PR locally and visit the following URL:


http://localhost:5400/website-server/#{%22steps%22:[{%22step%22:%22runPHP%22,%20%22code%22:%22%3C?php%20no_such_fn();%22}]}

It should reveal useful error information in the console.
  • Loading branch information
adamziel authored Jan 30, 2024
1 parent ceb8975 commit e74da08
Show file tree
Hide file tree
Showing 83 changed files with 575 additions and 169 deletions.
15 changes: 6 additions & 9 deletions packages/php-wasm/compile/php/php_wasm.c
Binary file modified packages/php-wasm/node/public/7_0_33/php_7_0.wasm
Binary file not shown.
Binary file modified packages/php-wasm/node/public/7_1_30/php_7_1.wasm
Binary file not shown.
Binary file modified packages/php-wasm/node/public/7_2_34/php_7_2.wasm
Binary file not shown.
Binary file modified packages/php-wasm/node/public/7_3_33/php_7_3.wasm
Binary file not shown.
Binary file modified packages/php-wasm/node/public/7_4_33/php_7_4.wasm
Binary file not shown.
Binary file modified packages/php-wasm/node/public/8_0_30/php_8_0.wasm
Binary file not shown.
Binary file modified packages/php-wasm/node/public/8_1_23/php_8_1.wasm
Binary file not shown.
Binary file modified packages/php-wasm/node/public/8_2_10/php_8_2.wasm
Binary file not shown.
Binary file modified packages/php-wasm/node/public/8_3_0/php_8_3.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_0.js
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_1.js
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_2.js
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_3.js
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_4.js
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_8_0.js
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_8_1.js
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_8_2.js
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_8_3.js
6 changes: 3 additions & 3 deletions packages/php-wasm/node/src/test/php-request-handler.spec.ts
94 changes: 93 additions & 1 deletion packages/php-wasm/node/src/test/php.spec.ts
18 changes: 16 additions & 2 deletions packages/php-wasm/universal/src/lib/base-php.ts
6 changes: 6 additions & 0 deletions packages/php-wasm/universal/src/lib/universal-php.ts
Binary file modified packages/php-wasm/web/public/kitchen-sink/7_0_33/php_7_0.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/kitchen-sink/7_1_30/php_7_1.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/kitchen-sink/7_2_34/php_7_2.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/kitchen-sink/7_3_33/php_7_3.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/kitchen-sink/7_4_33/php_7_4.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/kitchen-sink/8_0_30/php_8_0.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/kitchen-sink/8_1_23/php_8_1.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/kitchen-sink/8_2_10/php_8_2.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/kitchen-sink/8_3_0/php_8_3.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/kitchen-sink/php_7_0.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/kitchen-sink/php_7_1.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/kitchen-sink/php_7_2.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/kitchen-sink/php_7_3.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/kitchen-sink/php_7_4.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/kitchen-sink/php_8_0.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/kitchen-sink/php_8_1.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/kitchen-sink/php_8_2.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/kitchen-sink/php_8_3.js
Binary file modified packages/php-wasm/web/public/light/7_0_33/php_7_0.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/light/7_1_30/php_7_1.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/light/7_2_34/php_7_2.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/light/7_3_33/php_7_3.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/light/7_4_33/php_7_4.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/light/8_0_30/php_8_0.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/light/8_1_23/php_8_1.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/light/8_2_10/php_8_2.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/light/8_3_0/php_8_3.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/light/php_7_0.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/light/php_7_1.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/light/php_7_2.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/light/php_7_3.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/light/php_7_4.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/light/php_8_0.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/light/php_8_1.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/light/php_8_2.js
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/light/php_8_3.js
18 changes: 15 additions & 3 deletions packages/playground/blueprints/src/lib/compile.ts
55 changes: 55 additions & 0 deletions packages/playground/blueprints/src/lib/steps/cp.spec.ts
37 changes: 27 additions & 10 deletions packages/playground/blueprints/src/lib/steps/enable-multisite.ts
4 changes: 2 additions & 2 deletions packages/playground/blueprints/src/lib/steps/index.ts
37 changes: 14 additions & 23 deletions packages/playground/blueprints/src/lib/steps/install-plugin.ts
36 changes: 12 additions & 24 deletions packages/playground/blueprints/src/lib/steps/install-theme.ts
30 changes: 30 additions & 0 deletions packages/playground/blueprints/src/lib/steps/login.spec.ts
13 changes: 12 additions & 1 deletion packages/playground/blueprints/src/lib/steps/login.ts
55 changes: 55 additions & 0 deletions packages/playground/blueprints/src/lib/steps/mv.spec.ts
13 changes: 10 additions & 3 deletions packages/playground/blueprints/src/lib/steps/request.ts
37 changes: 37 additions & 0 deletions packages/playground/blueprints/src/lib/steps/rm.spec.ts
24 changes: 24 additions & 0 deletions packages/playground/blueprints/src/lib/steps/run-php.spec.ts
8 changes: 6 additions & 2 deletions packages/playground/blueprints/src/lib/steps/run-php.ts
57 changes: 23 additions & 34 deletions packages/playground/blueprints/src/lib/steps/site-data.ts
1 change: 0 additions & 1 deletion packages/playground/remote/src/lib/worker-thread.ts
5 changes: 5 additions & 0 deletions packages/playground/website/cypress/e2e/website-ui.cy.ts

0 comments on commit e74da08

Please sign in to comment.