| 200 | } |
| 201 | |
| 202 | async function withErrorHandling<T>(body: () => Promise<T>) { |
| 203 | return body().catch((e) => { |
| 204 | if (!(e instanceof Error)) throw e |
| 205 | const errnoException = e as NodeJS.ErrnoException |
| 206 | if (errnoException.code === "ENOENT") { |
| 207 | throw new NotFoundError({ message: `Resource not found: ${errnoException.path}` }) |
| 208 | } |
| 209 | // handle JSON parse errors gracefully |
| 210 | if (e instanceof SyntaxError && e.message.includes("JSON")) { |
| 211 | log.warn("corrupted JSON file, skipping", { error: e.message }) |
| 212 | throw new NotFoundError({ message: `Corrupted file: ${e.message}` }) |
| 213 | } |
| 214 | throw e |
| 215 | }) |
| 216 | } |
| 217 | |
| 218 | const glob = new Bun.Glob("**/*") |
| 219 | export async function list(prefix: string[]) { |