aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-class-map-generator/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-09 09:51:40 +0900
committernsfisis <nsfisis@gmail.com>2026-08-09 09:51:40 +0900
commita2f8edf2b7ccbb66bb93b811af82d575b9ac31ea (patch)
tree1d2f789a2fc63c35ac40e66d873481b6e3d1214b /crates/shirabe-class-map-generator/src
parentdfd98ce4b227a3a14dc913c669bee4f077a65178 (diff)
downloadphp-shirabe-a2f8edf2b7ccbb66bb93b811af82d575b9ac31ea.tar.gz
php-shirabe-a2f8edf2b7ccbb66bb93b811af82d575b9ac31ea.tar.zst
php-shirabe-a2f8edf2b7ccbb66bb93b811af82d575b9ac31ea.zip
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-class-map-generator/src')
-rw-r--r--crates/shirabe-class-map-generator/src/php_file_parser.rs78
1 files changed, 37 insertions, 41 deletions
diff --git a/crates/shirabe-class-map-generator/src/php_file_parser.rs b/crates/shirabe-class-map-generator/src/php_file_parser.rs
index 88676407..712fb4ab 100644
--- a/crates/shirabe-class-map-generator/src/php_file_parser.rs
+++ b/crates/shirabe-class-map-generator/src/php_file_parser.rs
@@ -4,9 +4,9 @@ use crate::php_file_cleaner::PhpFileCleaner;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
- CmpOp, HHVM_VERSION, PHP_EOL, PHP_VERSION_ID, RuntimeException, error_get_last, file_exists,
- file_get_contents, function_exists, is_file, is_readable, ltrim, php_strip_whitespace,
- str_replace_array, strrpos, substr, trim, version_compare,
+ CmpOp, HHVM_VERSION, PHP_EOL, PHP_VERSION_ID, RuntimeException, file_exists, file_get_contents,
+ function_exists, is_file, is_readable, ltrim, php_strip_whitespace, str_replace_array, strrpos,
+ substr, trim, version_compare,
};
use std::sync::OnceLock;
@@ -21,46 +21,42 @@ impl PhpFileParser {
}
// Use @ here instead of Silencer to actively suppress 'unhelpful' output
- let contents = php_strip_whitespace(path);
- if contents.is_empty() {
- let message: String;
- if !file_exists(path) {
- message = format!(
- "File at \"{}\" does not exist, check your classmap definitions",
- path
- );
- } else if !Self::is_readable(path) {
- message = format!(
- "File at \"{}\" is not readable, check its permissions",
- path
- );
- } else if trim(file_get_contents(path).unwrap_or_default().as_str(), None).is_empty() {
- // The input file was really empty and thus contains no classes
- return Ok(vec![]);
- } else {
- message = format!(
- "File at \"{}\" could not be parsed as PHP, it may be binary or corrupted",
- path
- );
- }
+ let contents = match php_strip_whitespace(path) {
+ Ok(contents) if !contents.is_empty() => contents,
+ stripped => {
+ let mut message: String;
+ if !file_exists(path) {
+ message = format!(
+ "File at \"{}\" does not exist, check your classmap definitions",
+ path
+ );
+ } else if !Self::is_readable(path) {
+ message = format!(
+ "File at \"{}\" is not readable, check its permissions",
+ path
+ );
+ } else if trim(file_get_contents(path).unwrap_or_default().as_str(), None)
+ .is_empty()
+ {
+ // The input file was really empty and thus contains no classes
+ return Ok(vec![]);
+ } else {
+ message = format!(
+ "File at \"{}\" could not be parsed as PHP, it may be binary or corrupted",
+ path
+ );
+ }
- let error = error_get_last();
- let mut message = message;
- if let Some(error) = error
- && let Some(err_msg) = error.get("message")
- {
- message = format!(
- "{}{}{}{}{}",
- message,
- PHP_EOL,
- "The following message may be helpful:",
- PHP_EOL,
- err_msg.as_string().unwrap_or("")
- );
- }
+ if let Err(error) = stripped {
+ message = format!(
+ "{}{}{}{}{}",
+ message, PHP_EOL, "The following message may be helpful:", PHP_EOL, error
+ );
+ }
- return Err(RuntimeException::new(message).into());
- }
+ return Err(RuntimeException::new(message).into());
+ }
+ };
// return early if there is no chance of matching anything in this file
let pattern = format!("{{\\b(?:class|interface|trait{})\\s}}i", extra_types);