From f1a88c8e62c9283f1d2d6210faaf860e4462a2e5 Mon Sep 17 00:00:00 2001 From: Joshua Gugun Siagian Date: Mon, 24 Feb 2025 12:03:39 +0700 Subject: [PATCH] improve stylesheet error handling --- assets/apps/dashboard/App.vue | 2 +- assets/packages/core/tailwindcss-v4/stylesheet.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/assets/apps/dashboard/App.vue b/assets/apps/dashboard/App.vue index 6d5f4f2..bff84ca 100644 --- a/assets/apps/dashboard/App.vue +++ b/assets/apps/dashboard/App.vue @@ -46,7 +46,7 @@ channel.addEventListener('message', async (e) => { notifier.success(`Cache generated in ${prettyMilliseconds(timeEnd - timeStart)}`); }, err => { - notifier.alert('Failed to generate cache'); + notifier.alert(`Failed to generate cache. Check the Browser's Console for more information.`); console.error('err', err); }, 'Generating cache...', diff --git a/assets/packages/core/tailwindcss-v4/stylesheet.js b/assets/packages/core/tailwindcss-v4/stylesheet.js index 97ca3d5..7fdaa02 100644 --- a/assets/packages/core/tailwindcss-v4/stylesheet.js +++ b/assets/packages/core/tailwindcss-v4/stylesheet.js @@ -22,6 +22,8 @@ export async function loadStylesheet(id, base, volume = {}) { ...twVolume }; + let _id = id; + if (isValidUrl(id)) { return { base: path.dirname(id), @@ -79,8 +81,17 @@ export async function loadStylesheet(id, base, volume = {}) { // fetch and store in volume await fetch(`https://esm.sh/${_path}`) - .then((response) => response.text()) - .then((data) => { + .then((response) => { + if (!response.ok) { + throw new Error( + _id.startsWith('.') + ? `Cannot find stylesheet '${_id}' on the Simple File System` + : `Cannot find stylesheet '${_id}' on the CDN` + ); + } + + let data = response.text(); + data = data // resolve the `@config '|"` imports paths to absolute paths with cdn .replace(/@config\s+['|"](.*)['|"]/g, (match, p1) => {