Repository: withastro/astro
File: packages/astro/src/core/errors/errors-data.ts (TypeScript)

Code before:
 * An unknown error occurred while reading or writing files to disk. It can be caused by many things, eg. missing permissions or a file not existing we attempt to read.
 */
export const UnknownFilesystemError = {
	name: 'UnknownFilesystemError',
	title: 'An unknown error occurred while reading or writing files to disk.',
	hint: 'It can be caused by many things, eg. missing permissions or a file not existing we attempt to read. Check the error cause for more details.',
} satisfies ErrorData;

/**
 * @docs
 * @description
 * Cannot extract the font type from the given URL.
 * @message
 * An error occured while trying to extract the font type from the given URL.
 */
export const CannotExtractFontType = {
	name: 'CannotExtractFontType',
	title: 'Cannot extract the font type from the given URL.',
	message: (url: string) => `An error occurred while trying to extract the font type from ${url}`,
	hint: 'Open an issue at https://github.com/withastro/astro/issues.',
} satisfies ErrorData;

/**
 * @docs
 * @description
 * Cannot extract the font data from the given URL.
 * @message
 * An error occured while trying to extract the font data from the given URL.
 */
export const CannotExtractFontData = {
	name: 'CannotExtractFontType',
	title: 'Cannot extract the font data from the given URL.',
	message: (family: string, url: string) => `An error occurred while trying to extract the font data from local font family "${family}" (url: ${url})`,
	hint: 'Update your family config and set \`weight\` and \`style\` manually instead.',
} satisfies ErrorData;

/**
 * @docs
 * @description
 * Cannot fetch the given font file
 * @message
 * An error occured while fetching font file from the given URL.
 */
export const CannotFetchFontFile = {
	name: 'CannotFetchFontFile',
	title: 'Cannot fetch the given font file.',
	message: (url: string) => `An error occurred while fetching the font file from ${url}`,
	hint: 'This is often caused by connectivity issues. If the error persists, open an issue at https://github.com/withastro/astro/issues.',
} satisfies ErrorData;

/**

Review comment (refactor):
Just noting that "font data" sounds a little vague compared to the hint about setting weight and style being the fix. (Data could be anything!) And, always thinking about being specific enough in case there's a different situation that is also, generically, about not being able to "extract data" or "read" a file but you need a slightly different error message in future.

Given the feature that this error message accompanies, and the hint provided, is the error more specifically something like (with whatever precise vocab makes sense) ... ?

> An error occurred while attempting to infer font family variations from a local font file

I wonder whether framing your title/message/description this way is more descriptive, relates better to the solution, and more future proof for adding other error messages that might later also depend on working with that local file?

Code after:
 * An unknown error occurred while reading or writing files to disk. It can be caused by many things, eg. missing permissions or a file not existing we attempt to read.
 */
export const UnknownFilesystemError = {
	name: 'UnknownFilesystemError',
	title: 'An unknown error occurred while reading or writing files to disk.',
	hint: 'It can be caused by many things, eg. missing permissions or a file not existing we attempt to read. Check the error cause for more details.',
} satisfies ErrorData;

/**
 * @docs
 * @description
 * Cannot extract the font type from the given URL.
 * @message
 * An error occured while trying to extract the font type from the given URL.
 */
export const CannotExtractFontType = {
	name: 'CannotExtractFontType',
	title: 'Cannot extract the font type from the given URL.',
	message: (url: string) => `An error occurred while trying to extract the font type from ${url}`,
	hint: 'Open an issue at https://github.com/withastro/astro/issues.',
} satisfies ErrorData;

/**
 * @docs
 * @description
 * Cannot determine weight and style from font file.
 * @message
 * An error occured while determining the weight and style from the local font file.
 */
export const CannotDetermineWeightAndStyleFromFontFile = {
	name: 'CannotDetermineWeightAndStyleFromFontFile',
	title: 'Cannot determine weight and style from font file.',
	message: (family: string, url: string) =>
		`An error occurred while determining the \`weight\` and \`style\` from local family "${family}" font file: ${url}`,
	hint: 'Update your family config and set `weight` and `style` manually instead.',
} satisfies ErrorData;

/**
 * @docs
 * @description
 * Cannot fetch the given font file
 * @message
 * An error occured while fetching font file from the given URL.
 */
export const CannotFetchFontFile = {
	name: 'CannotFetchFontFile',
	title: 'Cannot fetch the given font file.',
	message: (url: string) => `An error occurred while fetching the font file from ${url}`,
	hint: 'This is often caused by connectivity issues. If the error persists, open an issue at https://github.com/withastro/astro/issues.',
} satisfies ErrorData;