From a2f8edf2b7ccbb66bb93b811af82d575b9ac31ea Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 9 Aug 2026 09:51:40 +0900 Subject: feat(php-shim): replace error_get_last with the failing call's io::Error The shim raises no PHP-level errors, so error_get_last() always returned None and every message built from it lost its trailing reason. Now that the fs mutators and php_strip_whitespace carry an io::Error, take the reason from the call that actually failed instead of a global last-error slot. Filesystem::unlinkImplementation returns that error rather than a bool so ensureDirectoryExists, unlink and rmdir can report it, and PhpFileParser appends it to the "following message may be helpful" hint. The wording is Rust's io::Error text, not PHP's warning text, for the same reason noted in symfony/filesystem. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-php-shim/src/string.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'crates/shirabe-php-shim/src/string.rs') diff --git a/crates/shirabe-php-shim/src/string.rs b/crates/shirabe-php-shim/src/string.rs index 575bc16d..78688eed 100644 --- a/crates/shirabe-php-shim/src/string.rs +++ b/crates/shirabe-php-shim/src/string.rs @@ -846,17 +846,15 @@ pub fn ucfirst(s: &str) -> String { } } -pub fn php_strip_whitespace(path: impl AsRef) -> String { +pub fn php_strip_whitespace(path: impl AsRef) -> Result { // PHP `php_strip_whitespace()` tokenizes the source and re-emits it with comments removed and // each run of whitespace collapsed to a single space. There is no PHP tokenizer in the shim, so // this is a hand-written lexer that reproduces the observable effect for the cases the class-map // generator depends on: it preserves single-quoted, double-quoted, backtick and heredoc/nowdoc // string contents verbatim while dropping `//`, `#` and `/* */` comments and squeezing - // whitespace. On any read failure it returns an empty string, mirroring `@php_strip_whitespace`. - let contents = match std::fs::read(path.as_ref()) { - Ok(bytes) => bytes, - Err(_) => return String::new(), - }; + // whitespace. PHP returns an empty string on a read failure and leaves the reason in the warning + // text; this returns the io::Error instead so callers can report it. + let contents = std::fs::read(path.as_ref())?; let b = contents; let n = b.len(); @@ -981,7 +979,7 @@ pub fn php_strip_whitespace(path: impl AsRef) -> String { i += 1; } - String::from_utf8_lossy(&out).into_owned() + Ok(String::from_utf8_lossy(&out).into_owned()) } pub fn hexdec(_s: &str) -> i64 { -- cgit v1.3.1-4-g156e