Skip to content

Commit af80d7e

Browse files
committed
Improve error message for missing file that might be SVG
1 parent 21a9607 commit af80d7e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/common.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ namespace sharp {
398398
// From filesystem
399399
imageType = DetermineImageType(descriptor->file.data());
400400
if (imageType == ImageType::MISSING) {
401+
if (descriptor->file.find("<svg") != std::string::npos) {
402+
throw vips::VError("Input file is missing, did you mean "
403+
"sharp(Buffer.from('" + descriptor->file.substr(0, 8) + "...')?");
404+
}
401405
throw vips::VError("Input file is missing");
402406
}
403407
if (imageType != ImageType::UNKNOWN) {

test/unit/svg.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,11 @@ describe('SVG input', function () {
135135
assert.strictEqual(info.height, 240);
136136
assert.strictEqual(info.channels, 4);
137137
});
138+
139+
it('Detects SVG passed as a string', () =>
140+
assert.rejects(
141+
() => sharp('<svg></svg>').toBuffer(),
142+
/Input file is missing, did you mean/
143+
)
144+
);
138145
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy