0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Error when getImage() is passed an undefined src (#9423)

This commit is contained in:
Matthew Phillips 2023-12-13 09:24:46 -05:00 committed by GitHub
parent 836ab6214e
commit bda1d294f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Error when getImage is passed an undefined src

View file

@ -79,6 +79,12 @@ export async function getImage(
message: AstroErrorData.ExpectedImageOptions.message(JSON.stringify(options)),
});
}
if(typeof options.src === 'undefined') {
throw new AstroError({
...AstroErrorData.ExpectedImage,
message: AstroErrorData.ExpectedImage.message(options.src, 'undefined', JSON.stringify(options))
});
}
const service = await getConfiguredImageService();

View file

@ -640,14 +640,13 @@ describe('astro:image', () => {
expect(logs[0].message).to.contain('Expected getImage() parameter');
});
// TODO: For some reason, this error crashes the dev server?
it.skip('properly error when src is undefined', async () => {
it('properly error when src is undefined', async () => {
logs.length = 0;
let res = await fixture.fetch('/get-image-undefined');
await res.text();
expect(logs).to.have.a.lengthOf(1);
expect(logs[0].message).to.contain('Expected src to be an image.');
expect(logs[0].message).to.contain('Expected `src` property');
});
it('properly error image in Markdown frontmatter is not found', async () => {

View file

@ -1,5 +1,5 @@
---
import { getImage } from "astro:assets";
const myImage = getImage({src: undefined});
const myImage = await getImage({src: undefined});
---