Skip to content

Commit 73d293f

Browse files
committed
Use error handler instead of error suppression
Fixes #200.
1 parent 051211a commit 73d293f

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/Context/Internal/process-runner.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313

1414
// Doesn't exist in phpdbg...
1515
if (\function_exists("cli_set_process_title")) {
16-
@\cli_set_process_title("amp-process");
16+
\set_error_handler(static fn () => true);
17+
try {
18+
\cli_set_process_title("amp-process");
19+
} finally {
20+
\restore_error_handler();
21+
}
1722
}
1823

1924
(function (): void {

src/Context/ProcessContext.php

+16-10
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@ public static function start(
106106
self::$pharCopy = \sys_get_temp_dir() . "/phar-" . \bin2hex(\random_bytes(10)) . ".phar";
107107
\copy(\Phar::running(false), self::$pharCopy);
108108

109-
\register_shutdown_function(static function (): void {
110-
if (self::$pharCopy !== null) {
111-
@\unlink(self::$pharCopy);
112-
}
113-
});
109+
\register_shutdown_function(static fn () => self::unlinkExternalCopy(self::$pharCopy));
114110

115111
$path = "phar://" . self::$pharCopy . "/" . \substr($path, \strlen(\Phar::running(true)));
116112
}
@@ -121,11 +117,7 @@ public static function start(
121117
self::$pharScriptPath = $scriptPath = \sys_get_temp_dir() . "/amp-process-runner-" . $suffix . ".php";
122118
\file_put_contents($scriptPath, $contents);
123119

124-
\register_shutdown_function(static function (): void {
125-
if (self::$pharScriptPath !== null) {
126-
@\unlink(self::$pharScriptPath);
127-
}
128-
});
120+
\register_shutdown_function(static fn () => self::unlinkExternalCopy(self::$pharScriptPath));
129121
}
130122

131123
// Monkey-patch the script path in the same way, only supported if the command is given as array.
@@ -176,6 +168,20 @@ public static function start(
176168
return new self($process, $ipcChannel, $resultChannel);
177169
}
178170

171+
private static function unlinkExternalCopy(?string $filepath): void
172+
{
173+
if ($filepath === null) {
174+
return;
175+
}
176+
177+
\set_error_handler(static fn () => true);
178+
try {
179+
\unlink($filepath);
180+
} finally {
181+
\restore_error_handler();
182+
}
183+
}
184+
179185
/**
180186
* @return non-empty-list<string>
181187
*/

0 commit comments

Comments
 (0)