DenverCoder1/github-readme-streak-stats · error · InvalidArgumentException
500
500
Error message
Failed to convert SVG to PNG: {$error} What it means
convertSvgToPng() shells out to an external SVG-to-PNG converter (via shell_exec). If the command produces no stdout output, the library treats the conversion as failed and throws InvalidArgumentException with the converter's stderr text and code 500.
Solutions
- Install the external SVG conversion tool used by the command (e.g. rsvg-convert or ImageMagick) and confirm it is on PATH
- Run the shell command manually to see the real error output
- Verify the SVG input is valid XML and renders locally
- Check permissions and available memory for the conversion process
Example fix
// before (on server) // rsvg-convert not installed // after (Ubuntu/Debian) // sudo apt-get install librsvg2-bin
Defensive patterns
Strategy: try-catch
Validate before calling
if (shell_exec("command -v rsvg-convert") === null) { die("SVG converter binary not installed"); } Try / catch
try { $png = convertSvgToPng($svg); } catch (InvalidArgumentException $e) { error_log($e->getMessage()); http_response_code(500); echo "PNG conversion failed"; } Prevention
- Verify the converter binary exists during deployment health checks
- Validate SVG input before conversion
- Pin and document the converter dependency in your install scripts
When it happens
Trigger: The external converter binary is missing or not on PATH, is misconfigured, receives an invalid SVG, or runs out of memory, causing shell_exec to return empty output.
Common situations: Deployment environments without the required tool (e.g. rsvg-convert/inkscape/convert) installed; missing system libraries; an upstream SVG that the converter cannot parse.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
AI-assisted analysis of DenverCoder1/github-readme-streak-stats@70dd50f921 (2026-09-15).
Data as JSON: /api/errors/a66fef1d5dd84be5.
Report an issue: GitHub.
Appendix: source
Thrown at src/card.php:795
$svg = str_replace("\n", " ", $svg);
// escape svg for shell
$svg = escapeshellarg($svg);
// `--pipe`: read input from pipe (stdin)
// `--export-filename -`: write output to stdout
// `-w 495 -h 195`: set width and height of the output image
// `--export-type png`: set the output format to PNG
$cmd = "echo {$svg} | inkscape --pipe --export-filename - -w {$cardWidth} -h {$cardHeight} --export-type png";
// convert svg to png
$png = shell_exec($cmd); // skipcq: PHP-A1009
// check if the conversion was successful
if (empty($png)) {
// `2>&1`: redirect stderr to stdout
$error = shell_exec("$cmd 2>&1"); // skipcq: PHP-A1009
throw new InvalidArgumentException("Failed to convert SVG to PNG: {$error}", 500);
}
// return the generated png
return $png;
}
/**
* Return headers and response based on type
*
* @param string|array $output The stats (array) or error message (string) to display
* @param array<string,string>|NULL $params Request parameters
* @param int $errorCode The HTTP error code (used for JSON responses)
* @return array The Content-Type header and the response body, and status code in case of an error
*/
function generateOutput(string|array $output, ?array $params = null, int $errorCode = 200): array
{
$params = $params ?? $_REQUEST;
View on GitHub (pinned to 70dd50f921)