Skip to content

Commit 3a0c02a

Browse files
Its-Just-NansPrincesseuh
andauthoredMay 16, 2024··
add error message for svg without dimensions (#10924)
* add svg * throw clean error * add error handling * revert * throw clean error * add changeset * make it a patch * Update remoteProbe.ts --------- Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
1 parent 303968b commit 3a0c02a

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed
 

‎.changeset/cold-dolls-do.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"astro": patch
3+
---
4+
5+
Handle image-size errors by displaying a clearer message

‎packages/astro/src/assets/utils/metadata.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,28 @@ export async function imageMetadata(
66
data: Uint8Array,
77
src?: string
88
): Promise<Omit<ImageMetadata, 'src' | 'fsPath'>> {
9-
const result = probe(data);
9+
try {
10+
const result = probe(data);
11+
if (!result.height || !result.width || !result.type) {
12+
throw new AstroError({
13+
...AstroErrorData.NoImageMetadata,
14+
message: AstroErrorData.NoImageMetadata.message(src),
15+
});
16+
}
1017

11-
if (!result.height || !result.width || !result.type) {
18+
const { width, height, type, orientation } = result;
19+
const isPortrait = (orientation || 0) >= 5;
20+
21+
return {
22+
width: isPortrait ? height : width,
23+
height: isPortrait ? width : height,
24+
format: type as ImageInputFormat,
25+
orientation,
26+
};
27+
} catch (e) {
1228
throw new AstroError({
1329
...AstroErrorData.NoImageMetadata,
1430
message: AstroErrorData.NoImageMetadata.message(src),
1531
});
1632
}
17-
18-
const { width, height, type, orientation } = result;
19-
const isPortrait = (orientation || 0) >= 5;
20-
21-
return {
22-
width: isPortrait ? height : width,
23-
height: isPortrait ? width : height,
24-
format: type as ImageInputFormat,
25-
orientation,
26-
};
2733
}

0 commit comments

Comments
 (0)
Please sign in to comment.