Skip to content

Commit 4a56d0a

Browse files
jp-knjjp-knjematipico
authored
refactor(astro): Replaced generic Error throws with AstroError (#13759)
Co-authored-by: jp-knj <tomita.kenji1996@gmail.com> Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
1 parent 0decf32 commit 4a56d0a

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

.changeset/thin-regions-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Improved the error handling of certain error cases.

packages/astro/src/content/loaders/file.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url';
33
import yaml from 'js-yaml';
44
import { posixRelative } from '../utils.js';
55
import type { Loader, LoaderContext } from './types.js';
6+
import { AstroError } from '../../core/errors/index.js';
67

78
interface FileOptions {
89
/**
@@ -21,8 +22,10 @@ interface FileOptions {
2122
*/
2223
export function file(fileName: string, options?: FileOptions): Loader {
2324
if (fileName.includes('*')) {
24-
// TODO: AstroError
25-
throw new Error('Glob patterns are not supported in `file` loader. Use `glob` loader instead.');
25+
throw new AstroError({
26+
name: 'Glob Pattern Error',
27+
message: 'Glob patterns are not supported in `file` loader. Use `glob` loader instead.',
28+
});
2629
}
2730

2831
let parse: ((text: string) => any) | null = null;
@@ -39,10 +42,10 @@ export function file(fileName: string, options?: FileOptions): Loader {
3942
if (options?.parser) parse = options.parser;
4043

4144
if (parse === null) {
42-
// TODO: AstroError
43-
throw new Error(
44-
`No parser found for file '${fileName}'. Try passing a parser to the \`file\` loader.`,
45-
);
45+
throw new AstroError({
46+
name: 'Parser Not Found',
47+
message: `No parser found for file '${fileName}'. Try passing a parser to the \`file\` loader.`,
48+
});
4649
}
4750

4851
async function syncData(filePath: string, { logger, parseData, store, config }: LoaderContext) {

0 commit comments

Comments
 (0)