Core: Improve error message of remark image

This commit is contained in:
Fuma Nama
2025-05-08 23:16:01 +08:00
parent a989d3cd75
commit c05dc03d28
2 changed files with 17 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-core': patch
---
Improve error message of remark image
+12 -6
View File
@@ -113,11 +113,12 @@ export function remarkImage({
});
})
.catch((e) => {
console.error(
`[Remark Image] Failed obtain image size for ${url} with public directory ${publicDir}`,
throw new Error(
`[Remark Image] Failed obtain image size for ${url} (public directory configured as ${publicDir})`,
{
cause: e,
},
);
throw e;
});
promises.push(task);
@@ -217,7 +218,12 @@ async function getImageSize(
return imageSizeFromFile(isRelative ? path.join(dir, src) : src);
}
const buffer = await fetch(url).then((res) => res.arrayBuffer());
const res = await fetch(url);
if (!res.ok) {
throw new Error(
`[Remark Image] Failed to fetch ${url} (${res.status}): ${await res.text()}`,
);
}
return imageSize(new Uint8Array(buffer));
return imageSize(new Uint8Array(await res.arrayBuffer()));
}