Skip to content

Commit bda1d29

Browse files
authoredDec 13, 2023
Error when getImage() is passed an undefined src (#9423)
1 parent 836ab62 commit bda1d29

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed
 

‎.changeset/brown-apricots-kick.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Error when getImage is passed an undefined src

‎packages/astro/src/assets/internal.ts

+6
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ export async function getImage(
7979
message: AstroErrorData.ExpectedImageOptions.message(JSON.stringify(options)),
8080
});
8181
}
82+
if(typeof options.src === 'undefined') {
83+
throw new AstroError({
84+
...AstroErrorData.ExpectedImage,
85+
message: AstroErrorData.ExpectedImage.message(options.src, 'undefined', JSON.stringify(options))
86+
});
87+
}
8288

8389
const service = await getConfiguredImageService();
8490

‎packages/astro/test/core-image.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -640,14 +640,13 @@ describe('astro:image', () => {
640640
expect(logs[0].message).to.contain('Expected getImage() parameter');
641641
});
642642

643-
// TODO: For some reason, this error crashes the dev server?
644-
it.skip('properly error when src is undefined', async () => {
643+
it('properly error when src is undefined', async () => {
645644
logs.length = 0;
646645
let res = await fixture.fetch('/get-image-undefined');
647646
await res.text();
648647

649648
expect(logs).to.have.a.lengthOf(1);
650-
expect(logs[0].message).to.contain('Expected src to be an image.');
649+
expect(logs[0].message).to.contain('Expected `src` property');
651650
});
652651

653652
it('properly error image in Markdown frontmatter is not found', async () => {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
import { getImage } from "astro:assets";
33
4-
const myImage = getImage({src: undefined});
4+
const myImage = await getImage({src: undefined});
55
---

0 commit comments

Comments
 (0)
Please sign in to comment.