aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/http
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-13 23:18:41 +0900
committernsfisis <nsfisis@gmail.com>2026-06-13 23:18:41 +0900
commite165b2ffa32e21c50787ae7227dc5333131d1414 (patch)
treea10e4218bcb93085ebbe3acb5369fdc1d88176c8 /crates/shirabe/src/util/http
parent69c372ba0eca61b05260d6d208445d9e69d14e34 (diff)
downloadphp-shirabe-e165b2ffa32e21c50787ae7227dc5333131d1414.tar.gz
php-shirabe-e165b2ffa32e21c50787ae7227dc5333131d1414.tar.zst
php-shirabe-e165b2ffa32e21c50787ae7227dc5333131d1414.zip
refactor(http): drop unworkable set_error_handler warning capture
PHP wraps fopen/file_get_contents/file_put_contents in set_error_handler to capture warning text into error_message. Rust reports I/O failures through return values rather than warnings, so this side channel cannot work; replace the calls with TODO(phase-c) notes and leave error_message empty until the I/O layer surfaces a reason. Also remove the now-unused set_error_handler_closure shim and make set_error_handler a no-op. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/http')
-rw-r--r--crates/shirabe/src/util/http/curl_downloader.rs25
1 files changed, 7 insertions, 18 deletions
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs
index f1056cc..37993f9 100644
--- a/crates/shirabe/src/util/http/curl_downloader.rs
+++ b/crates/shirabe/src/util/http/curl_downloader.rs
@@ -20,9 +20,8 @@ use shirabe_php_shim::{
curl_multi_select, curl_multi_setopt, curl_setopt, curl_setopt_array, curl_share_init,
curl_share_setopt, curl_strerror, curl_version, defined, explode, fclose, fopen,
function_exists, implode, in_array, ini_get, is_resource, json_decode, max, parse_url,
- preg_quote, rename, restore_error_handler, rewind, rtrim, set_error_handler_closure, sprintf,
- str_contains, stream_get_contents, stream_get_contents_with_max, stripos, strpos, substr,
- unlink_silent, usleep, var_export,
+ preg_quote, rename, rewind, rtrim, sprintf, str_contains, stream_get_contents,
+ stream_get_contents_with_max, stripos, strpos, substr, unlink_silent, usleep, var_export,
};
use crate::config::Config;
@@ -362,28 +361,18 @@ impl CurlDownloader {
"php://temp/maxmemory:524288".to_string()
};
- let error_message: std::rc::Rc<std::cell::RefCell<String>> =
- std::rc::Rc::new(std::cell::RefCell::new(String::new()));
- {
- let error_message = error_message.clone();
- set_error_handler_closure(Box::new(move |_code: i64, msg: &str| -> bool {
- let mut em = error_message.borrow_mut();
- if !em.is_empty() {
- em.push_str("\n");
- }
- em.push_str(&Preg::replace(r"{^fopen\(.*?\): }", "", msg).unwrap_or_default());
- true
- }));
- }
+ // TODO(phase-c): PHP wraps this fopen in a set_error_handler to capture the warning text
+ // (stripping the "fopen(...): " prefix) into the message. Rust I/O reports failures through
+ // return values, not warnings, so error_message stays empty until fopen surfaces its reason.
+ let error_message = String::new();
let body_handle = fopen(&body_target, "w+b");
- restore_error_handler();
if matches!(body_handle, PhpMixed::Bool(false)) {
return Ok(Err(TransportException::new(
format!(
"The \"{}\" file could not be written to {}: {}",
url,
copy_to.unwrap_or("a temporary file"),
- error_message.borrow()
+ error_message
),
0,
)));