Skip to content

Commit 0f5aac5

Browse files
authored
fix: file based snippets do not handle fatal errors
1 parent c566ced commit 0f5aac5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/php/snippet-ops.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,22 @@ function execute_snippet_from_flat_file( $code, $file, int $id = 0, bool $force
750750
return false;
751751
}
752752

753-
require_once $file;
753+
ob_start();
754+
755+
try {
756+
require_once $file;
757+
$result = null;
758+
} catch ( ParseError $parse_error ) {
759+
$result = $parse_error;
760+
} catch ( Error $error ) {
761+
$result = $error;
762+
} catch ( Throwable $throwable ) {
763+
$result = $throwable;
764+
}
765+
766+
ob_end_clean();
754767

755768
do_action( 'code_snippets/after_execute_snippet_from_flat_file', $file, $id );
769+
770+
return $result ?? null;
756771
}

0 commit comments

Comments
 (0)