Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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/moody-apples-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

follow a pattern for errors that is putting them in errors-data
10 changes: 4 additions & 6 deletions packages/astro/src/content/loaders/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import yaml from 'js-yaml';
import { AstroError } from '../../core/errors/index.js';
import { posixRelative } from '../utils.js';
import type { Loader, LoaderContext } from './types.js';
import { FileGlobNotSupported, FileParserNotFound } from '../../core/errors/errors-data.js';

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

let parse: ((text: string) => any) | null = null;
Expand All @@ -43,8 +41,8 @@ export function file(fileName: string, options?: FileOptions): Loader {

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

Expand Down
34 changes: 34 additions & 0 deletions packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,40 @@ export const FontFamilyNotFound = {
hint: 'This is often caused by a typo. Check that your Font component is using a `cssVariable` specified in your config.',
} satisfies ErrorData;

/**
* @docs
* @message No parser found for file `example.md`. Pass a parser to the `file` loader (e.g. `parser: mdx`).
* @see
* - [parsers](https://docs.astro.build/en/guides/imports/#parsers)
* @description
* Thrown when the `file` loader can’t determine which parser to use.
*/
export const FileParserNotFound = {
name: 'FileParserNotFound',
title: 'File parser not found',
message: (fileName: string) =>
`No parser was found for '${fileName}'. Pass a parser function (e.g. \`parser: mdx\`) to the \`file\` loader.`,
hint:
'See https://docs.astro.build/en/guides/imports/#parsers for the list of available parser options.',
} satisfies ErrorData;

/**
* @docs
* @message Glob patterns are not supported in the `file` loader. Use the `glob` loader instead.
* @see
* - [glob patterns](https://docs.astro.build/en/guides/imports/#glob-patterns)
* @description
* Thrown when a glob pattern is supplied to the `file` loader.
*/
export const FileGlobNotSupported = {
name: 'FileGlobNotSupported',
title: 'Glob patterns are not supported in the file loader',
message:
'Glob patterns are not supported in the `file` loader. Use the `glob` loader instead.',
hint:
'See https://docs.astro.build/en/guides/imports/#glob-patterns for supported glob usage.',
} satisfies ErrorData;

/**
* @docs
* @kind heading
Expand Down