From 1384576cd5ac5c6283812d2bdc4225df648c3922 Mon Sep 17 00:00:00 2001 From: Tom Sommer Date: Fri, 9 Oct 2026 17:39:14 +0200 Subject: [PATCH] Report why fetching an IANA bootstrap file failed When file_get_contents() fails (for example with allow_url_fopen=0), the PHP warning was swallowed and the error claimed the URL returned invalid data. Throw with the first warning instead. --- src/Services/AbstractRdapService.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Services/AbstractRdapService.php b/src/Services/AbstractRdapService.php index 43dbfef..a3c6103 100644 --- a/src/Services/AbstractRdapService.php +++ b/src/Services/AbstractRdapService.php @@ -394,7 +394,9 @@ public static function fromURL(string $url) : static && is_writable(dirname($fileCache)) ? $fileCache : null; } } - set_error_handler(static function (int $code, string $message, string $file, int $line) : bool { + $errorMessage = null; + set_error_handler(static function (int $code, string $message) use (&$errorMessage) : bool { + $errorMessage ??= $message; error_clear_last(); return true; }); @@ -406,8 +408,17 @@ public static function fromURL(string $url) : static ) : null ); restore_error_handler(); + if (!is_string($content)) { + throw new InvalidServiceDefinitionException( + sprintf( + 'Could not fetch protocol service URL "%s": %s', + $url, + $errorMessage ?? 'unknown error' + ) + ); + } - $service = static::fromJson(is_string($content) ? $content : '', $url); + $service = static::fromJson($content, $url); if ($fileCache) { file_put_contents($fileCache, $content); }