mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Improve error message for missing file that might be SVG
This commit is contained in:
parent
21a960796c
commit
af80d7e389
@ -398,6 +398,10 @@ namespace sharp {
|
|||||||
// From filesystem
|
// From filesystem
|
||||||
imageType = DetermineImageType(descriptor->file.data());
|
imageType = DetermineImageType(descriptor->file.data());
|
||||||
if (imageType == ImageType::MISSING) {
|
if (imageType == ImageType::MISSING) {
|
||||||
|
if (descriptor->file.find("<svg") != std::string::npos) {
|
||||||
|
throw vips::VError("Input file is missing, did you mean "
|
||||||
|
"sharp(Buffer.from('" + descriptor->file.substr(0, 8) + "...')?");
|
||||||
|
}
|
||||||
throw vips::VError("Input file is missing");
|
throw vips::VError("Input file is missing");
|
||||||
}
|
}
|
||||||
if (imageType != ImageType::UNKNOWN) {
|
if (imageType != ImageType::UNKNOWN) {
|
||||||
|
@ -135,4 +135,11 @@ describe('SVG input', function () {
|
|||||||
assert.strictEqual(info.height, 240);
|
assert.strictEqual(info.height, 240);
|
||||||
assert.strictEqual(info.channels, 4);
|
assert.strictEqual(info.channels, 4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Detects SVG passed as a string', () =>
|
||||||
|
assert.rejects(
|
||||||
|
() => sharp('<svg></svg>').toBuffer(),
|
||||||
|
/Input file is missing, did you mean/
|
||||||
|
)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user