Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thin-regions-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

refactor: replace Error with AstroError
15 changes: 9 additions & 6 deletions packages/astro/src/content/loaders/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url';
import yaml from 'js-yaml';
import { posixRelative } from '../utils.js';
import type { Loader, LoaderContext } from './types.js';
import { AstroError } from '../../core/errors/index.js';

interface FileOptions {
/**
Expand All @@ -21,8 +22,10 @@ interface FileOptions {
*/
export function file(fileName: string, options?: FileOptions): Loader {
if (fileName.includes('*')) {
// TODO: AstroError
throw new Error('Glob patterns are not supported in `file` loader. Use `glob` loader instead.');
throw new AstroError({
name: 'Glob Pattern Error',
message: 'Glob patterns are not supported in `file` loader. Use `glob` loader instead.',
});
}

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

if (parse === null) {
// TODO: AstroError
throw new Error(
`No parser found for file '${fileName}'. Try passing a parser to the \`file\` loader.`,
);
throw new AstroError({
name: 'Parser Not Found',
message: `No parser found for file '${fileName}'. Try passing a parser to the \`file\` loader.`,
});
}

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