feat: break down AstroErrorData
in multiple objects
This commit is contained in:
parent
93ad8b95e3
commit
46974b64e7
43 changed files with 1226 additions and 1154 deletions
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
import { getImage, type LocalImageProps, type RemoteImageProps } from 'astro:assets';
|
||||
import { AstroError, AstroErrorData } from '../dist/core/errors/index.js';
|
||||
import { AstroError } from '../dist/core/errors/index.js';
|
||||
import { ImageMissingAlt } from '../dist/core/errors/errors-data.js';
|
||||
|
||||
// The TypeScript diagnostic for JSX props uses the last member of the union to suggest props, so it would be better for
|
||||
// LocalImageProps to be last. Unfortunately, when we do this the error messages that remote images get are complete nonsense
|
||||
|
@ -10,7 +11,7 @@ type Props = LocalImageProps | RemoteImageProps;
|
|||
const props = Astro.props;
|
||||
|
||||
if (props.alt === undefined || props.alt === null) {
|
||||
throw new AstroError(AstroErrorData.ImageMissingAlt);
|
||||
throw new AstroError(ImageMissingAlt);
|
||||
}
|
||||
|
||||
// As a convenience, allow width and height to be string with a number in them, to match HTML's native `img`.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import type { AstroSettings } from '../@types/astro.js';
|
||||
import { AstroError, AstroErrorData } from '../core/errors/index.js';
|
||||
import { AstroError } from '../core/errors/index.js';
|
||||
import * as AstroErrorData from '../core/errors/errors-data.js';
|
||||
import { isLocalService, type ImageService } from './services/service.js';
|
||||
import type { GetImageResult, ImageMetadata, ImageTransform } from './types.js';
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { AstroError, AstroErrorData } from '../../core/errors/index.js';
|
||||
import { AstroError } from '../../core/errors/index.js';
|
||||
import * as AstroErrorData from '../../core/errors/errors-data.js';
|
||||
import { joinPaths } from '../../core/path.js';
|
||||
import { VALID_SUPPORTED_FORMATS } from '../consts.js';
|
||||
import { isESMImportedImage } from '../internal.js';
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import type { MarkdownHeading } from '@astrojs/markdown-remark';
|
||||
import { ZodIssueCode, string as zodString } from 'zod';
|
||||
import { AstroError, AstroErrorData } from '../core/errors/index.js';
|
||||
import { AstroError } from '../core/errors/index.js';
|
||||
import * as AstroErrorData from '../core/errors/errors-data.js';
|
||||
import { prependForwardSlash } from '../core/path.js';
|
||||
import {
|
||||
createComponent,
|
||||
|
|
|
@ -5,7 +5,7 @@ import * as path from 'node:path';
|
|||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import { normalizePath, type ViteDevServer } from 'vite';
|
||||
import type { AstroSettings, ContentEntryType } from '../@types/astro.js';
|
||||
import { AstroErrorData } from '../core/errors/errors-data.js';
|
||||
import * as AstroErrorData from '../core/errors/errors-data.js';
|
||||
import { AstroError } from '../core/errors/errors.js';
|
||||
import { info, warn, type LogOptions } from '../core/logger/core.js';
|
||||
import { isRelativePath } from '../core/path.js';
|
||||
|
|
|
@ -14,7 +14,8 @@ import type {
|
|||
ImageInputFormat,
|
||||
} from '../@types/astro.js';
|
||||
import { VALID_INPUT_FORMATS } from '../assets/consts.js';
|
||||
import { AstroError, AstroErrorData } from '../core/errors/index.js';
|
||||
import { AstroError } from '../core/errors/index.js';
|
||||
import * as AstroErrorData from '../core/errors/errors-data.js';
|
||||
|
||||
import { formatYAMLException, isYAMLException } from '../core/errors/utils.js';
|
||||
import { CONTENT_FLAGS, CONTENT_TYPES_FILE } from './consts.js';
|
||||
|
|
|
@ -12,7 +12,7 @@ import type {
|
|||
DataEntryModule,
|
||||
DataEntryType,
|
||||
} from '../@types/astro.js';
|
||||
import { AstroErrorData } from '../core/errors/errors-data.js';
|
||||
import * as AstroErrorData from '../core/errors/errors-data.js';
|
||||
import { AstroError } from '../core/errors/errors.js';
|
||||
import { escapeViteEnvReferences } from '../vite-plugin-utils/index.js';
|
||||
import { CONTENT_FLAG, DATA_FLAG } from './consts.js';
|
||||
|
@ -371,6 +371,7 @@ function stringifyEntryData(data: Record<string, any>): string {
|
|||
});
|
||||
} else {
|
||||
throw new AstroError({
|
||||
name: 'ContentImportsPluginError',
|
||||
message: 'Unexpected error processing content collection data.',
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
|
|||
import pLimit from 'p-limit';
|
||||
import type { Plugin } from 'vite';
|
||||
import type { AstroSettings, ContentEntryType } from '../@types/astro.js';
|
||||
import { AstroError, AstroErrorData } from '../core/errors/index.js';
|
||||
import { AstroError } from '../core/errors/index.js';
|
||||
import * as AstroErrorData from '../core/errors/errors-data.js';
|
||||
import { appendForwardSlash } from '../core/path.js';
|
||||
import { rootRelativePath } from '../core/util.js';
|
||||
import { VIRTUAL_MODULE_ID } from './consts.js';
|
||||
|
|
|
@ -35,7 +35,8 @@ import {
|
|||
import { runHookBuildGenerated } from '../../integrations/index.js';
|
||||
import { isServerLikeOutput } from '../../prerender/utils.js';
|
||||
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
import { debug, info } from '../logger/core.js';
|
||||
import { RedirectSinglePageBuiltModule, getRedirectLocationOrThrow } from '../redirects/index.js';
|
||||
import { isEndpointResult } from '../render/core.js';
|
||||
|
|
|
@ -12,13 +12,14 @@ import {
|
|||
eachPageData,
|
||||
type BuildInternals,
|
||||
} from '../../core/build/internal.js';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
import { emptyDir, removeEmptyDirs } from '../../core/fs/index.js';
|
||||
import { appendForwardSlash, prependForwardSlash } from '../../core/path.js';
|
||||
import { isModeServerWithNoAdapter } from '../../core/util.js';
|
||||
import { runHookBuildSetup } from '../../integrations/index.js';
|
||||
import { isServerLikeOutput } from '../../prerender/utils.js';
|
||||
import { PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import { info } from '../logger/core.js';
|
||||
import { routeIsRedirect } from '../redirects/index.js';
|
||||
import { getOutDirWithinCwd } from './common.js';
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import type { TransformResult } from '@astrojs/compiler';
|
||||
import type { ResolvedConfig } from 'vite';
|
||||
import type { AstroConfig } from '../../@types/astro';
|
||||
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
import { transform } from '@astrojs/compiler';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { normalizePath } from 'vite';
|
||||
import { AggregateError, AstroError, CompilerError } from '../errors/errors.js';
|
||||
import { AstroErrorData } from '../errors/index.js';
|
||||
import { resolvePath } from '../util.js';
|
||||
import { createStylePreprocessor } from './style.js';
|
||||
|
||||
|
@ -87,6 +86,7 @@ function handleCompileResultErrors(result: TransformResult, cssTransformErrors:
|
|||
|
||||
if (compilerError) {
|
||||
throw new CompilerError({
|
||||
name: 'CompilerError',
|
||||
message: compilerError.text,
|
||||
location: {
|
||||
line: compilerError.location.line,
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import type { TransformOptions } from '@astrojs/compiler';
|
||||
import fs from 'node:fs';
|
||||
import { preprocessCSS, type ResolvedConfig } from 'vite';
|
||||
import { AstroErrorData, CSSError, positionAt } from '../errors/index.js';
|
||||
import { CSSError, positionAt } from '../errors/index.js';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
|
||||
export function createStylePreprocessor({
|
||||
filename,
|
||||
|
@ -88,6 +89,7 @@ function enhanceCSSError(err: any, filename: string, cssContent: string) {
|
|||
errorPosition.line += 1;
|
||||
|
||||
return new CSSError({
|
||||
name: 'CSSError',
|
||||
message: err.message,
|
||||
location: {
|
||||
file: filename,
|
||||
|
|
|
@ -6,7 +6,7 @@ import type {
|
|||
AstroUserConfig,
|
||||
CLIFlags,
|
||||
} from '../../@types/astro';
|
||||
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
import * as colors from 'kleur/colors';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
@ -14,7 +14,7 @@ import { fileURLToPath } from 'node:url';
|
|||
import { ZodError } from 'zod';
|
||||
import { eventConfigError, telemetry } from '../../events/index.js';
|
||||
import { trackAstroConfigZodError } from '../errors/errors.js';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import { formatConfigErrorMessage } from '../messages.js';
|
||||
import { mergeConfig } from './merge.js';
|
||||
import { createRelativeSchema } from './schema.js';
|
||||
|
|
|
@ -6,7 +6,8 @@ import { getContentPaths } from '../../content/index.js';
|
|||
import jsxRenderer from '../../jsx/renderer.js';
|
||||
import { markdownContentEntryType } from '../../vite-plugin-markdown/content-entry-type.js';
|
||||
import { getDefaultClientDirectives } from '../client-directive/index.js';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
import { formatYAMLException, isYAMLException } from '../errors/utils.js';
|
||||
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../constants.js';
|
||||
import { AstroTimer } from './timer.js';
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import type { CookieSerializeOptions } from 'cookie';
|
||||
import { parse, serialize } from 'cookie';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
|
||||
interface AstroCookieSetOptions {
|
||||
domain?: string;
|
||||
|
|
|
@ -10,9 +10,10 @@ import type { Environment, RenderContext } from '../render/index';
|
|||
import { renderEndpoint } from '../../runtime/server/index.js';
|
||||
import { ASTRO_VERSION } from '../constants.js';
|
||||
import { AstroCookies, attachToResponse } from '../cookies/index.js';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import { warn } from '../logger/core.js';
|
||||
import { callMiddleware } from '../middleware/callMiddleware.js';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
|
||||
const clientAddressSymbol = Symbol.for('astro.clientAddress');
|
||||
const clientLocalsSymbol = Symbol.for('astro.locals');
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
**Error Format**
|
||||
|
||||
Name (key of the object definition):
|
||||
Name:
|
||||
|
||||
- This property is a static reference to the error. The shape should be similar to JavaScript's native errors (TypeError, ReferenceError): pascal-cased, no spaces, no special characters etc. (ex: `ClientAddressNotAvailable`)
|
||||
- This is the only part of the error message that should not be written as a full, proper sentence complete with Capitalization and end punctuation.
|
||||
|
@ -19,8 +19,8 @@ Title:
|
|||
|
||||
Message:
|
||||
|
||||
- Begin with **what happened** and **why**. (ex: `Could not use {feature} because Server-side Rendering is not enabled.`)
|
||||
- Then, **describe the action the user should take**. (ex: `Update your Astro config with `output: 'server'` to enable Server-side Rendering.`)
|
||||
- Begin with **what happened** and **why**. (ex: `Could not use {feature} because Server-side Rendering is not enabled.`)
|
||||
- Then, **describe the action the user should take**. (ex: `Update your Astro config with `output: 'server'` to enable Server-side Rendering.`)
|
||||
- Although this does not need to be as brief as the `title`, try to keep sentences short, clear and direct to give the reader all the necessary information quickly as possible.
|
||||
- Instead of writing a longer message, consider using a `hint`.
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url';
|
|||
import { getHighlighter } from 'shiki';
|
||||
import type { ErrorPayload } from 'vite';
|
||||
import type { ModuleLoader } from '../../module-loader/index.js';
|
||||
import { AstroErrorData } from '../errors-data.js';
|
||||
import { FailedToLoadModuleSSR, InvalidGlob, MdxIntegrationMissingError } from '../errors-data.js';
|
||||
import { AstroError, type ErrorWithMetadata } from '../errors.js';
|
||||
import { createSafeError } from '../utils.js';
|
||||
import type { SSRLoadedRenderer } from './../../../@types/astro.js';
|
||||
|
@ -41,10 +41,10 @@ export function enhanceViteSSRError({
|
|||
// https://github.com/vitejs/vite/blob/ee7c28a46a6563d54b828af42570c55f16b15d2c/packages/vite/src/node/ssr/ssrModuleLoader.ts#L91
|
||||
let importName: string | undefined;
|
||||
if ((importName = safeError.message.match(/Failed to load url (.*?) \(resolved id:/)?.[1])) {
|
||||
safeError.title = AstroErrorData.FailedToLoadModuleSSR.title;
|
||||
safeError.title = FailedToLoadModuleSSR.title;
|
||||
safeError.name = 'FailedToLoadModuleSSR';
|
||||
safeError.message = AstroErrorData.FailedToLoadModuleSSR.message(importName);
|
||||
safeError.hint = AstroErrorData.FailedToLoadModuleSSR.hint;
|
||||
safeError.message = FailedToLoadModuleSSR.message(importName);
|
||||
safeError.hint = FailedToLoadModuleSSR.hint;
|
||||
const line = lns.findIndex((ln) => ln.includes(importName!));
|
||||
|
||||
if (line !== -1) {
|
||||
|
@ -68,8 +68,8 @@ export function enhanceViteSSRError({
|
|||
fileId?.match(/\.mdx$/)
|
||||
) {
|
||||
safeError = new AstroError({
|
||||
...AstroErrorData.MdxIntegrationMissingError,
|
||||
message: AstroErrorData.MdxIntegrationMissingError.message(JSON.stringify(fileId)),
|
||||
...MdxIntegrationMissingError,
|
||||
message: MdxIntegrationMissingError.message(JSON.stringify(fileId)),
|
||||
location: safeError.loc,
|
||||
stack: safeError.stack,
|
||||
}) as ErrorWithMetadata;
|
||||
|
@ -80,10 +80,10 @@ export function enhanceViteSSRError({
|
|||
const globPattern = safeError.message.match(/glob: "(.+)" \(/)?.[1];
|
||||
|
||||
if (globPattern) {
|
||||
safeError.message = AstroErrorData.InvalidGlob.message(globPattern);
|
||||
safeError.message = InvalidGlob.message(globPattern);
|
||||
safeError.name = 'InvalidGlob';
|
||||
safeError.hint = AstroErrorData.InvalidGlob.hint;
|
||||
safeError.title = AstroErrorData.InvalidGlob.title;
|
||||
safeError.hint = InvalidGlob.hint;
|
||||
safeError.title = InvalidGlob.title;
|
||||
|
||||
const line = lns.findIndex((ln) => ln.includes(globPattern));
|
||||
|
||||
|
@ -137,7 +137,7 @@ export async function getViteErrorPayload(err: ErrorWithMetadata): Promise<Astro
|
|||
const message = renderErrorMarkdown(err.message.trim(), 'html');
|
||||
const hint = err.hint ? renderErrorMarkdown(err.hint.trim(), 'html') : undefined;
|
||||
|
||||
const hasDocs = err.name in AstroErrorData;
|
||||
const hasDocs = !!err.name;
|
||||
const docslink = hasDocs
|
||||
? `https://docs.astro.build/en/reference/errors/${getKebabErrorName(err.name)}/`
|
||||
: undefined;
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
import type { ZodError } from 'zod';
|
||||
|
||||
export interface ErrorData {
|
||||
name: string;
|
||||
title: string;
|
||||
message?: string | ((...params: any) => string);
|
||||
hint?: string | ((...params: any) => string);
|
||||
}
|
||||
|
||||
export const AstroErrorData = {
|
||||
/**
|
||||
* @docs
|
||||
* @kind heading
|
||||
|
@ -27,10 +27,11 @@ export const AstroErrorData = {
|
|||
*
|
||||
* If there isn't one already, please [create an issue](https://astro.build/issues/compiler).
|
||||
*/
|
||||
UnknownCompilerError: {
|
||||
export const UnknownCompilerError = {
|
||||
name: 'UnknownCompilerError',
|
||||
title: 'Unknown compiler error.',
|
||||
hint: 'This is almost always a problem with the Astro compiler, not your code. Please open an issue at https://astro.build/issues/compiler.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
// 1xxx and 2xxx codes are reserved for compiler errors and warnings respectively
|
||||
/**
|
||||
* @docs
|
||||
|
@ -43,12 +44,13 @@ export const AstroErrorData = {
|
|||
* To redirect on a static website, the [meta refresh attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta) can be used. Certain hosts also provide config-based redirects (ex: [Netlify redirects](https://docs.netlify.com/routing/redirects/)).
|
||||
* @deprecated since version 2.6
|
||||
*/
|
||||
StaticRedirectNotAvailable: {
|
||||
export const StaticRedirectNotAvailable = {
|
||||
name: 'StaticRedirectNotAvailable',
|
||||
title: '`Astro.redirect` is not available in static mode.',
|
||||
message:
|
||||
"Redirects are only available when using `output: 'server'` or `output: 'hybrid'`. Update your Astro config if you need SSR features.",
|
||||
hint: 'See https://docs.astro.build/en/guides/server-side-rendering/#enabling-ssr-in-your-project for more information on how to enable SSR.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -57,11 +59,12 @@ export const AstroErrorData = {
|
|||
* @description
|
||||
* The adapter you're using unfortunately does not support `Astro.clientAddress`.
|
||||
*/
|
||||
ClientAddressNotAvailable: {
|
||||
export const ClientAddressNotAvailable = {
|
||||
name: 'ClientAddressNotAvailable',
|
||||
title: '`Astro.clientAddress` is not available in current adapter.',
|
||||
message: (adapterName: string) =>
|
||||
`\`Astro.clientAddress\` is not available in the \`${adapterName}\` adapter. File an issue with the adapter to add support.`,
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -72,12 +75,13 @@ export const AstroErrorData = {
|
|||
*
|
||||
* To get the user's IP address in static mode, different APIs such as [Ipify](https://www.ipify.org/) can be used in a [Client-side script](https://docs.astro.build/en/guides/client-side-scripts/) or it may be possible to get the user's IP using a serverless function hosted on your hosting provider.
|
||||
*/
|
||||
StaticClientAddressNotAvailable: {
|
||||
export const StaticClientAddressNotAvailable = {
|
||||
name: 'StaticClientAddressNotAvailable',
|
||||
title: '`Astro.clientAddress` is not available in static mode.',
|
||||
message:
|
||||
"`Astro.clientAddress` is only available when using `output: 'server'` or `output: 'hybrid'`. Update your Astro config if you need SSR features.",
|
||||
hint: 'See https://docs.astro.build/en/guides/server-side-rendering/#enabling-ssr-in-your-project for more information on how to enable SSR.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -85,13 +89,14 @@ export const AstroErrorData = {
|
|||
* @description
|
||||
* A [dynamic route](https://docs.astro.build/en/core-concepts/routing/#dynamic-routes) was matched, but no corresponding path was found for the requested parameters. This is often caused by a typo in either the generated or the requested path.
|
||||
*/
|
||||
NoMatchingStaticPathFound: {
|
||||
export const NoMatchingStaticPathFound = {
|
||||
name: 'NoMatchingStaticPathFound',
|
||||
title: 'No static path found for requested path.',
|
||||
message: (pathName: string) =>
|
||||
`A \`getStaticPaths()\` route pattern was matched, but no matching static path was found for requested path \`${pathName}\`.`,
|
||||
hint: (possibleRoutes: string[]) =>
|
||||
`Possible dynamic routes being matched: ${possibleRoutes.join(', ')}.`,
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message Route returned a `RETURNED_VALUE`. Only a Response can be returned from Astro files.
|
||||
|
@ -112,14 +117,15 @@ export const AstroErrorData = {
|
|||
* ```
|
||||
*
|
||||
*/
|
||||
OnlyResponseCanBeReturned: {
|
||||
export const OnlyResponseCanBeReturned = {
|
||||
name: 'OnlyResponseCanBeReturned',
|
||||
title: 'Invalid type returned by Astro page.',
|
||||
message: (route: string | undefined, returnedValue: string) =>
|
||||
`Route \`${
|
||||
route ? route : ''
|
||||
}\` returned a \`${returnedValue}\`. Only a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) can be returned from Astro files.`,
|
||||
hint: 'See https://docs.astro.build/en/guides/server-side-rendering/#response for more information.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -131,11 +137,12 @@ export const AstroErrorData = {
|
|||
* <Counter client:media="(max-width: 640px)" />
|
||||
* ```
|
||||
*/
|
||||
MissingMediaQueryDirective: {
|
||||
export const MissingMediaQueryDirective = {
|
||||
name: 'MissingMediaQueryDirective',
|
||||
title: 'Missing value for `client:media` directive.',
|
||||
message:
|
||||
'Media query not provided for `client:media` directive. A media query similar to `client:media="(max-width: 600px)"` must be provided',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message Unable to render `COMPONENT_NAME`. There are `RENDERER_COUNT` renderer(s) configured in your `astro.config.mjs` file, but none were able to server-side render `COMPONENT_NAME`.
|
||||
|
@ -147,7 +154,8 @@ export const AstroErrorData = {
|
|||
*
|
||||
* For JSX / TSX files, [@astrojs/react](https://docs.astro.build/en/guides/integrations-guide/react/), [@astrojs/preact](https://docs.astro.build/en/guides/integrations-guide/preact/) or [@astrojs/solid-js](https://docs.astro.build/en/guides/integrations-guide/solid-js/) can be used. For Vue and Svelte files, the [@astrojs/vue](https://docs.astro.build/en/guides/integrations-guide/vue/) and [@astrojs/svelte](https://docs.astro.build/en/guides/integrations-guide/svelte/) integrations can be used respectively
|
||||
*/
|
||||
NoMatchingRenderer: {
|
||||
export const NoMatchingRenderer = {
|
||||
name: 'NoMatchingRenderer',
|
||||
title: 'No matching renderer found.',
|
||||
message: (
|
||||
componentName: string,
|
||||
|
@ -171,7 +179,7 @@ but ${plural ? 'none were' : 'it was not'} able to server-side render \`${compon
|
|||
}`,
|
||||
hint: (probableRenderers: string) =>
|
||||
`Did you mean to enable the ${probableRenderers} integration?\n\nSee https://docs.astro.build/en/core-concepts/framework-components/ for more information on how to install and configure integrations.`,
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -181,12 +189,13 @@ but ${plural ? 'none were' : 'it was not'} able to server-side render \`${compon
|
|||
* Astro tried to hydrate a component on the client, but the renderer used does not provide a client entrypoint to use to hydrate.
|
||||
*
|
||||
*/
|
||||
NoClientEntrypoint: {
|
||||
export const NoClientEntrypoint = {
|
||||
name: 'NoClientEntrypoint',
|
||||
title: 'No client entrypoint specified in renderer.',
|
||||
message: (componentName: string, clientDirective: string, rendererName: string) =>
|
||||
`\`${componentName}\` component has a \`client:${clientDirective}\` directive, but no client entrypoint was provided by \`${rendererName}\`.`,
|
||||
hint: 'See https://docs.astro.build/en/reference/integrations-reference/#addrenderer-option for more information on how to configure your renderer.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -199,13 +208,14 @@ but ${plural ? 'none were' : 'it was not'} able to server-side render \`${compon
|
|||
* <SomeReactComponent client:only="react" />
|
||||
* ```
|
||||
*/
|
||||
NoClientOnlyHint: {
|
||||
export const NoClientOnlyHint = {
|
||||
name: 'NoClientOnlyHint',
|
||||
title: 'Missing hint on client:only directive.',
|
||||
message: (componentName: string) =>
|
||||
`Unable to render \`${componentName}\`. When using the \`client:only\` hydration strategy, Astro needs a hint to use the correct renderer.`,
|
||||
hint: (probableRenderers: string) =>
|
||||
`Did you mean to pass \`client:only="${probableRenderers}"\`? See https://docs.astro.build/en/reference/directives-reference/#clientonly for more information on client:only`,
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -225,12 +235,13 @@ but ${plural ? 'none were' : 'it was not'} able to server-side render \`${compon
|
|||
*---
|
||||
* ```
|
||||
*/
|
||||
InvalidGetStaticPathParam: {
|
||||
export const InvalidGetStaticPathParam = {
|
||||
name: 'InvalidGetStaticPathParam',
|
||||
title: 'Invalid value returned by a `getStaticPaths` path.',
|
||||
message: (paramType) =>
|
||||
`Invalid params given to \`getStaticPaths\` path. Expected an \`object\`, got \`${paramType}\``,
|
||||
hint: 'See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -247,12 +258,13 @@ but ${plural ? 'none were' : 'it was not'} able to server-side render \`${compon
|
|||
*}
|
||||
* ```
|
||||
*/
|
||||
InvalidGetStaticPathsEntry: {
|
||||
export const InvalidGetStaticPathsEntry = {
|
||||
name: 'InvalidGetStaticPathsEntry',
|
||||
title: "Invalid entry inside getStaticPath's return value",
|
||||
message: (entryType) =>
|
||||
`Invalid entry returned by getStaticPaths. Expected an object, got \`${entryType}\``,
|
||||
hint: "If you're using a `.map` call, you might be looking for `.flatMap()` instead. See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths.",
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -270,12 +282,13 @@ but ${plural ? 'none were' : 'it was not'} able to server-side render \`${compon
|
|||
*}
|
||||
* ```
|
||||
*/
|
||||
InvalidGetStaticPathsReturn: {
|
||||
export const InvalidGetStaticPathsReturn = {
|
||||
name: 'InvalidGetStaticPathsReturn',
|
||||
title: 'Invalid value returned by getStaticPaths.',
|
||||
message: (returnType) =>
|
||||
`Invalid type returned by \`getStaticPaths\`. Expected an \`array\`, got \`${returnType}\``,
|
||||
hint: 'See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
|
||||
/**
|
||||
* @docs
|
||||
|
@ -284,12 +297,13 @@ but ${plural ? 'none were' : 'it was not'} able to server-side render \`${compon
|
|||
* @description
|
||||
* `getStaticPaths` no longer expose an helper for generating a RSS feed. We recommend migrating to the [@astrojs/rss](https://docs.astro.build/en/guides/rss/#setting-up-astrojsrss)integration instead.
|
||||
*/
|
||||
GetStaticPathsRemovedRSSHelper: {
|
||||
export const GetStaticPathsRemovedRSSHelper = {
|
||||
name: 'GetStaticPathsRemovedRSSHelper',
|
||||
title: 'getStaticPaths RSS helper is not available anymore.',
|
||||
message:
|
||||
'The RSS helper has been removed from `getStaticPaths`. Try the new @astrojs/rss package instead.',
|
||||
hint: 'See https://docs.astro.build/en/guides/rss/ for more information.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -310,11 +324,12 @@ but ${plural ? 'none were' : 'it was not'} able to server-side render \`${compon
|
|||
* ```
|
||||
* Will create the following route: `site.com/blog/1`.
|
||||
*/
|
||||
GetStaticPathsExpectedParams: {
|
||||
export const GetStaticPathsExpectedParams = {
|
||||
name: 'GetStaticPathsExpectedParams',
|
||||
title: 'Missing params property on `getStaticPaths` route.',
|
||||
message: 'Missing or empty required `params` property on `getStaticPaths` route.',
|
||||
hint: 'See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -349,12 +364,13 @@ but ${plural ? 'none were' : 'it was not'} able to server-side render \`${compon
|
|||
* ---
|
||||
* ```
|
||||
*/
|
||||
GetStaticPathsInvalidRouteParam: {
|
||||
export const GetStaticPathsInvalidRouteParam = {
|
||||
name: 'GetStaticPathsInvalidRouteParam',
|
||||
title: 'Invalid value for `getStaticPaths` route parameter.',
|
||||
message: (key: string, value: any, valueType: any) =>
|
||||
`Invalid getStaticPaths route parameter for \`${key}\`. Expected undefined, a string or a number, received \`${valueType}\` (\`${value}\`)`,
|
||||
hint: 'See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -364,7 +380,8 @@ but ${plural ? 'none were' : 'it was not'} able to server-side render \`${compon
|
|||
* @description
|
||||
* In [Static Mode](https://docs.astro.build/en/core-concepts/routing/#static-ssg-mode), all routes must be determined at build time. As such, dynamic routes must `export` a `getStaticPaths` function returning the different paths to generate.
|
||||
*/
|
||||
GetStaticPathsRequired: {
|
||||
export const GetStaticPathsRequired = {
|
||||
name: 'GetStaticPathsRequired',
|
||||
title: '`getStaticPaths()` function required for dynamic routes.',
|
||||
message:
|
||||
'`getStaticPaths()` function is required for dynamic routes. Make sure that you `export` a `getStaticPaths` function from your dynamic route.',
|
||||
|
@ -372,7 +389,7 @@ but ${plural ? 'none were' : 'it was not'} able to server-side render \`${compon
|
|||
|
||||
Alternatively, set \`output: "server"\` in your Astro config file to switch to a non-static server build. This error can also occur if using \`export const prerender = true;\`.
|
||||
See https://docs.astro.build/en/guides/server-side-rendering/ for more information on non-static rendering.`,
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -380,11 +397,12 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* Certain words cannot be used for slot names due to being already used internally.
|
||||
*/
|
||||
ReservedSlotName: {
|
||||
export const ReservedSlotName = {
|
||||
name: 'ReservedSlotName',
|
||||
title: 'Invalid slot name.',
|
||||
message: (slotName: string) =>
|
||||
`Unable to create a slot named \`${slotName}\`. \`${slotName}\` is a reserved slot name. Please update the name of this slot.`,
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -393,22 +411,24 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* To use server-side rendering, an adapter needs to be installed so Astro knows how to generate the proper output for your targeted deployment platform.
|
||||
*/
|
||||
NoAdapterInstalled: {
|
||||
export const NoAdapterInstalled = {
|
||||
name: 'NoAdapterInstalled',
|
||||
title: 'Cannot use Server-side Rendering without an adapter.',
|
||||
message: `Cannot use \`output: 'server'\` or \`output: 'hybrid'\` without an adapter. Please install and configure the appropriate server adapter for your final deployment.`,
|
||||
hint: 'See https://docs.astro.build/en/guides/server-side-rendering/ for more information.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @description
|
||||
* No import statement was found for one of the components. If there is an import statement, make sure you are using the same identifier in both the imports and the component usage.
|
||||
*/
|
||||
NoMatchingImport: {
|
||||
export const NoMatchingImport = {
|
||||
name: 'NoMatchingImport',
|
||||
title: 'No import found for component.',
|
||||
message: (componentName: string) =>
|
||||
`Could not render \`${componentName}\`. No matching import has been found for \`${componentName}\`.`,
|
||||
hint: 'Please make sure the component is properly imported.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message
|
||||
|
@ -417,7 +437,8 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* The `prerender` feature only supports a subset of valid JavaScript — be sure to use exactly `export const prerender = true` so that our compiler can detect this directive at build time. Variables, `let`, and `var` declarations are not supported.
|
||||
*/
|
||||
InvalidPrerenderExport: {
|
||||
export const InvalidPrerenderExport = {
|
||||
name: 'InvalidPrerenderExport',
|
||||
title: 'Invalid prerender export.',
|
||||
message: (prefix: string, suffix: string, isHydridOuput: boolean) => {
|
||||
const defaultExpectedValue = isHydridOuput ? 'false' : 'true';
|
||||
|
@ -428,7 +449,7 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
return msg;
|
||||
},
|
||||
hint: 'Mutable values declared at runtime are not supported. Please make sure to use exactly `export const prerender = true`.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message
|
||||
|
@ -437,11 +458,12 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* Astro components cannot be rendered manually via a function call, such as `Component()` or `{items.map(Component)}`. Prefer the component syntax `<Component />` or `{items.map(item => <Component {...item} />)}`.
|
||||
*/
|
||||
InvalidComponentArgs: {
|
||||
export const InvalidComponentArgs = {
|
||||
name: 'InvalidComponentArgs',
|
||||
title: 'Invalid component arguments.',
|
||||
message: (name: string) => `Invalid arguments passed to${name ? ` <${name}>` : ''} component.`,
|
||||
hint: 'Astro components cannot be rendered directly via function call, such as `Component()` or `{items.map(Component)}`.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -449,12 +471,13 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* The page number parameter was not found in your filepath.
|
||||
*/
|
||||
PageNumberParamNotFound: {
|
||||
export const PageNumberParamNotFound = {
|
||||
name: 'PageNumberParamNotFound',
|
||||
title: 'Page number param not found.',
|
||||
message: (paramName: string) =>
|
||||
`[paginate()] page number param \`${paramName}\` not found in your filepath.`,
|
||||
hint: 'Rename your file to `[page].astro` or `[...page].astro`.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -466,11 +489,12 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
*
|
||||
* If the image is merely decorative (i.e. doesn’t contribute to the understanding of the page), set `alt=""` so that screen readers know to ignore the image.
|
||||
*/
|
||||
ImageMissingAlt: {
|
||||
export const ImageMissingAlt = {
|
||||
name: 'ImageMissingAlt',
|
||||
title: 'Missing alt property.',
|
||||
message: 'The alt property is required.',
|
||||
hint: "The `alt` property is important for the purpose of accessibility, without it users using screen readers or other assistive technologies won't be able to understand what your image is supposed to represent. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-alt for more information.",
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -480,11 +504,12 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
*
|
||||
* If you believe that your service is properly configured and this error is wrong, please [open an issue](https://astro.build/issues/).
|
||||
*/
|
||||
InvalidImageService: {
|
||||
export const InvalidImageService = {
|
||||
name: 'InvalidImageService',
|
||||
title: 'Error while loading image service.',
|
||||
message:
|
||||
'There was an error loading the configured image service. Please see the stack trace for more information.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message
|
||||
|
@ -497,16 +522,15 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
*
|
||||
* If your image is inside your `src` folder, you probably meant to import it instead. See [the Imports guide for more information](https://docs.astro.build/en/guides/imports/#other-assets).
|
||||
*/
|
||||
MissingImageDimension: {
|
||||
export const MissingImageDimension = {
|
||||
name: 'MissingImageDimension',
|
||||
title: 'Missing image dimensions',
|
||||
message: (missingDimension: 'width' | 'height' | 'both', imageURL: string) =>
|
||||
`Missing ${
|
||||
missingDimension === 'both'
|
||||
? 'width and height attributes'
|
||||
: `${missingDimension} attribute`
|
||||
missingDimension === 'both' ? 'width and height attributes' : `${missingDimension} attribute`
|
||||
} for ${imageURL}. When using remote images, both dimensions are always required in order to avoid CLS.`,
|
||||
hint: 'If your image is inside your `src` folder, you probably meant to import it instead. See [the Imports guide for more information](https://docs.astro.build/en/guides/imports/#other-assets).',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @description
|
||||
|
@ -521,14 +545,15 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* <img src={rocket.src} width={rocket.width} height={rocket.height} alt="A rocketship in space." />
|
||||
* ```
|
||||
*/
|
||||
UnsupportedImageFormat: {
|
||||
export const UnsupportedImageFormat = {
|
||||
name: 'UnsupportedImageFormat',
|
||||
title: 'Unsupported image format',
|
||||
message: (format: string, imagePath: string, supportedFormats: readonly string[]) =>
|
||||
`Received unsupported format \`${format}\` from \`${imagePath}\`. Currently only ${supportedFormats.join(
|
||||
', '
|
||||
)} are supported by our image services.`,
|
||||
hint: "Using an `img` tag directly instead of the `Image` component might be what you're looking for.",
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -539,13 +564,14 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
*
|
||||
* If you cannot prevent passing `undefined`, then an additional extension can be added to the endpoint file name to generate the file with a different name. For example, renaming `pages/api/[slug].ts` to `pages/api/[slug].json.ts`.
|
||||
*/
|
||||
PrerenderDynamicEndpointPathCollide: {
|
||||
export const PrerenderDynamicEndpointPathCollide = {
|
||||
name: 'PrerenderDynamicEndpointPathCollide',
|
||||
title: 'Prerendered dynamic endpoint has path collision.',
|
||||
message: (pathname: string) =>
|
||||
`Could not render \`${pathname}\` with an \`undefined\` param as the generated path will collide during prerendering. Prevent passing \`undefined\` as \`params\` for the endpoint's \`getStaticPaths()\` function, or add an additional extension to the endpoint's filename.`,
|
||||
hint: (filename: string) =>
|
||||
`Rename \`${filename}\` to \`${filename.replace(/\.(js|ts)/, (m) => `.json` + m)}\``,
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -565,12 +591,13 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
*
|
||||
* In most cases, this error happens when the value passed to `src` is undefined.
|
||||
*/
|
||||
ExpectedImage: {
|
||||
export const ExpectedImage = {
|
||||
name: 'ExpectedImage',
|
||||
title: 'Expected src to be an image.',
|
||||
message: (options: string) =>
|
||||
`Expected \`src\` property to be either an ESM imported image or a string with the path of a remote image. Received \`${options}\`.`,
|
||||
hint: 'This error can often happen because of a wrong path. Make sure the path to your image is correct.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -587,11 +614,12 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
*
|
||||
* In most cases, this error happens because parameters were passed directly instead of inside an object.
|
||||
*/
|
||||
ExpectedImageOptions: {
|
||||
export const ExpectedImageOptions = {
|
||||
name: 'ExpectedImageOptions',
|
||||
title: 'Expected image options.',
|
||||
message: (options: string) =>
|
||||
`Expected getImage() parameter to be an object. Received \`${options}\`.`,
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message
|
||||
|
@ -603,23 +631,25 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
*
|
||||
* Images in Markdown are relative to the current file. To refer to an image that is located in the same folder as the `.md` file, the path should start with `./`
|
||||
*/
|
||||
MarkdownImageNotFound: {
|
||||
export const MarkdownImageNotFound = {
|
||||
name: 'MarkdownImageNotFound',
|
||||
title: 'Image not found.',
|
||||
message: (imagePath: string, fullImagePath: string | undefined) =>
|
||||
`Could not find requested image \`${imagePath}\`${
|
||||
fullImagePath ? ` at \`${fullImagePath}\`.` : '.'
|
||||
}`,
|
||||
hint: 'This is often caused by a typo in the image path. Please make sure the file exists, and is spelled correctly.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @description
|
||||
* Making changes to the response, such as setting headers, cookies, and the status code cannot be done outside of page components.
|
||||
*/
|
||||
ResponseSentError: {
|
||||
export const ResponseSentError = {
|
||||
name: 'ResponseSentError',
|
||||
title: 'Unable to set response.',
|
||||
message: 'The response has already been sent to the browser and cannot be altered.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
|
||||
/**
|
||||
* @docs
|
||||
|
@ -635,11 +665,11 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* });
|
||||
* ```
|
||||
*/
|
||||
MiddlewareNoDataOrNextCalled: {
|
||||
export const MiddlewareNoDataOrNextCalled = {
|
||||
name: 'MiddlewareNoDataOrNextCalled',
|
||||
title: "The middleware didn't return a response or call `next`.",
|
||||
message:
|
||||
'The middleware needs to either return a `Response` object or call the `next` function.',
|
||||
},
|
||||
message: 'The middleware needs to either return a `Response` object or call the `next` function.',
|
||||
} satisfies ErrorData;
|
||||
|
||||
/**
|
||||
* @docs
|
||||
|
@ -654,10 +684,11 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* });
|
||||
* ```
|
||||
*/
|
||||
MiddlewareNotAResponse: {
|
||||
export const MiddlewareNotAResponse = {
|
||||
name: 'MiddlewareNotAResponse',
|
||||
title: 'The middleware returned something that is not a `Response` object.',
|
||||
message: 'Any data returned from middleware must be a valid `Response` object.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
|
||||
/**
|
||||
* @docs
|
||||
|
@ -674,12 +705,13 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* });
|
||||
* ```
|
||||
*/
|
||||
LocalsNotAnObject: {
|
||||
export const LocalsNotAnObject = {
|
||||
name: 'LocalsNotAnObject',
|
||||
title: 'Value assigned to `locals` is not accepted.',
|
||||
message:
|
||||
'`locals` can only be assigned to an object. Other values like numbers, strings, etc. are not accepted.',
|
||||
hint: 'If you tried to remove some information from the `locals` object, try to use `delete` or set the property to `undefined`.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -700,11 +732,12 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* <Image src={myImage.src} alt="Cool image" />
|
||||
* ```
|
||||
*/
|
||||
LocalImageUsedWrongly: {
|
||||
export const LocalImageUsedWrongly = {
|
||||
name: 'LocalImageUsedWrongly',
|
||||
title: 'ESM imported images must be passed as-is.',
|
||||
message: (imageFilePath: string) =>
|
||||
`\`Image\`'s and \`getImage\`'s \`src\` parameter must be an imported image or an URL, it cannot be a filepath. Received \`${imageFilePath}\`.`,
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
|
||||
/**
|
||||
* @docs
|
||||
|
@ -713,12 +746,13 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* `Astro.glob()` can only be used in `.astro` files. You can use [`import.meta.glob()`](https://vitejs.dev/guide/features.html#glob-import) instead to acheive the same result.
|
||||
*/
|
||||
AstroGlobUsedOutside: {
|
||||
export const AstroGlobUsedOutside = {
|
||||
name: 'AstroGlobUsedOutside',
|
||||
title: 'Astro.glob() used outside of an Astro file.',
|
||||
message: (globStr: string) =>
|
||||
`\`Astro.glob(${globStr})\` can only be used in \`.astro\` files. \`import.meta.glob(${globStr})\` can be used instead to achieve a similar result.`,
|
||||
hint: "See Vite's documentation on `import.meta.glob` for more information: https://vitejs.dev/guide/features.html#glob-import",
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
|
||||
/**
|
||||
* @docs
|
||||
|
@ -727,11 +761,12 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* `Astro.glob()` did not return any matching files. There might be a typo in the glob pattern.
|
||||
*/
|
||||
AstroGlobNoMatch: {
|
||||
export const AstroGlobNoMatch = {
|
||||
name: 'AstroGlobNoMatch',
|
||||
title: 'Astro.glob() did not match any files.',
|
||||
message: (globStr: string) =>
|
||||
`\`Astro.glob(${globStr})\` did not return any matching files. Check the pattern for typos.`,
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -739,9 +774,10 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* A redirect must be given a location with the `Location` header.
|
||||
*/
|
||||
RedirectWithNoLocation: {
|
||||
export const RedirectWithNoLocation = {
|
||||
name: 'RedirectWithNoLocation',
|
||||
title: 'A redirect must be given a location with the `Location` header.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -749,11 +785,12 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* A dynamic route param is invalid. This is often caused by an `undefined` parameter or a missing [rest parameter](https://docs.astro.build/en/core-concepts/routing/#rest-parameters).
|
||||
*/
|
||||
InvalidDynamicRoute: {
|
||||
export const InvalidDynamicRoute = {
|
||||
name: 'InvalidDynamicRoute',
|
||||
title: 'Invalid dynamic route.',
|
||||
message: (route: string, invalidParam: string, received: string) =>
|
||||
`The ${invalidParam} param for route ${route} is invalid. Received **${received}**.`,
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
// No headings here, that way Vite errors are merged with Astro ones in the docs, which makes more sense to users.
|
||||
// Vite Errors - 4xxx
|
||||
/**
|
||||
|
@ -765,9 +802,10 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
*
|
||||
* If you can reliably cause this error to happen, we'd appreciate if you could [open an issue](https://astro.build/issues/)
|
||||
*/
|
||||
UnknownViteError: {
|
||||
export const UnknownViteError = {
|
||||
name: 'UnknownViteError',
|
||||
title: 'Unknown Vite Error.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -777,11 +815,12 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
*
|
||||
* This message can also appear when a type is imported without specifying that it is a [type import](https://docs.astro.build/en/guides/typescript/#type-imports).
|
||||
*/
|
||||
FailedToLoadModuleSSR: {
|
||||
export const FailedToLoadModuleSSR = {
|
||||
name: 'FailedToLoadModuleSSR',
|
||||
title: 'Could not import file.',
|
||||
message: (importName: string) => `Could not import \`${importName}\`.`,
|
||||
hint: 'This is often caused by a typo in the import path. Please make sure the file exists.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -789,22 +828,24 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* Astro encountered an invalid glob pattern. This is often caused by the glob pattern not being a valid file path.
|
||||
*/
|
||||
InvalidGlob: {
|
||||
export const InvalidGlob = {
|
||||
name: 'InvalidGlob',
|
||||
title: 'Invalid glob pattern.',
|
||||
message: (globPattern: string) =>
|
||||
`Invalid glob pattern: \`${globPattern}\`. Glob patterns must start with './', '../' or '/'.`,
|
||||
hint: 'See https://docs.astro.build/en/guides/imports/#glob-patterns for more information on supported glob patterns.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @description
|
||||
* Astro couldn't find the correct page to render, probably because it wasn't correctly mapped for SSR usage. This is an internal error.
|
||||
*/
|
||||
FailedToFindPageMapSSR: {
|
||||
export const FailedToFindPageMapSSR = {
|
||||
name: 'FailedToFindPageMapSSR',
|
||||
title: "Astro couldn't find the correct page to render",
|
||||
message:
|
||||
"Astro couldn't find the correct page to render, probably because it wasn't correctly mapped for SSR usage. This is an internal error. Please file an issue.",
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @kind heading
|
||||
|
@ -818,9 +859,10 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* Astro encountered an unknown error while parsing your CSS. Oftentimes, this is caused by a syntax error and the error message should contain more information.
|
||||
*/
|
||||
UnknownCSSError: {
|
||||
export const UnknownCSSError = {
|
||||
name: 'UnknownCSSError',
|
||||
title: 'Unknown CSS Error.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message
|
||||
|
@ -830,9 +872,10 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* Astro encountered an error while parsing your CSS, due to a syntax error. This is often caused by a missing semicolon.
|
||||
*/
|
||||
CSSSyntaxError: {
|
||||
export const CSSSyntaxError = {
|
||||
name: 'CSSSyntaxError',
|
||||
title: 'CSS Syntax Error.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @kind heading
|
||||
|
@ -844,9 +887,10 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* Astro encountered an unknown error while parsing your Markdown. Oftentimes, this is caused by a syntax error and the error message should contain more information.
|
||||
*/
|
||||
UnknownMarkdownError: {
|
||||
export const UnknownMarkdownError = {
|
||||
name: 'UnknownMarkdownError',
|
||||
title: 'Unknown Markdown Error.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message
|
||||
|
@ -858,9 +902,10 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* Astro encountered an error while parsing the frontmatter of your Markdown file.
|
||||
* This is often caused by a mistake in the syntax, such as a missing colon or a missing end quote.
|
||||
*/
|
||||
MarkdownFrontmatterParseError: {
|
||||
export const MarkdownFrontmatterParseError = {
|
||||
name: 'MarkdownFrontmatterParseError',
|
||||
title: 'Failed to parse Markdown frontmatter.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -868,12 +913,13 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* A remark or rehype plugin attempted to inject invalid frontmatter. This occurs when "astro.frontmatter" is set to `null`, `undefined`, or an invalid JSON object.
|
||||
*/
|
||||
InvalidFrontmatterInjectionError: {
|
||||
export const InvalidFrontmatterInjectionError = {
|
||||
name: 'InvalidFrontmatterInjectionError',
|
||||
title: 'Invalid frontmatter injection.',
|
||||
message:
|
||||
'A remark or rehype plugin attempted to inject invalid frontmatter. Ensure "astro.frontmatter" is set to a valid JSON object that is not `null` or `undefined`.',
|
||||
hint: 'See the frontmatter injection docs https://docs.astro.build/en/guides/markdown-content/#modifying-frontmatter-programmatically for more information.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -881,12 +927,13 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* Unable to find the official `@astrojs/mdx` integration. This error is raised when using MDX files without an MDX integration installed.
|
||||
*/
|
||||
MdxIntegrationMissingError: {
|
||||
export const MdxIntegrationMissingError = {
|
||||
name: 'MdxIntegrationMissingError',
|
||||
title: 'MDX integration missing.',
|
||||
message: (file: string) =>
|
||||
`Unable to render ${file}. Ensure that the \`@astrojs/mdx\` integration is installed.`,
|
||||
hint: 'See the MDX integration docs for installation and usage instructions: https://docs.astro.build/en/guides/integrations-guide/mdx/',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
// Config Errors - 7xxx
|
||||
/**
|
||||
* @docs
|
||||
|
@ -898,9 +945,10 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
*
|
||||
* If you can reliably cause this error to happen, we'd appreciate if you could [open an issue](https://astro.build/issues/)
|
||||
*/
|
||||
UnknownConfigError: {
|
||||
export const UnknownConfigError = {
|
||||
name: 'UnknownConfigError',
|
||||
title: 'Unknown configuration error.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -908,11 +956,12 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* The specified configuration file using `--config` could not be found. Make sure that it exists or that the path is correct
|
||||
*/
|
||||
ConfigNotFound: {
|
||||
export const ConfigNotFound = {
|
||||
name: 'ConfigNotFound',
|
||||
title: 'Specified configuration file not found.',
|
||||
message: (configFile: string) =>
|
||||
`Unable to resolve \`--config "${configFile}"\`. Does the file exist?`,
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -920,11 +969,12 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* Astro detected a legacy configuration option in your configuration file.
|
||||
*/
|
||||
ConfigLegacyKey: {
|
||||
export const ConfigLegacyKey = {
|
||||
name: 'ConfigLegacyKey',
|
||||
title: 'Legacy configuration detected.',
|
||||
message: (legacyConfigKey: string) => `Legacy configuration detected: \`${legacyConfigKey}\`.`,
|
||||
hint: 'Please update your configuration to the new format.\nSee https://astro.build/config for more information.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @kind heading
|
||||
|
@ -938,9 +988,10 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
*
|
||||
* If you can reliably cause this error to happen, we'd appreciate if you could [open an issue](https://astro.build/issues/)
|
||||
*/
|
||||
UnknownCLIError: {
|
||||
export const UnknownCLIError = {
|
||||
name: 'UnknownCLIError',
|
||||
title: 'Unknown CLI Error.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @description
|
||||
|
@ -948,12 +999,13 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @see
|
||||
* - [Content collections documentation](https://docs.astro.build/en/guides/content-collections/)
|
||||
*/
|
||||
GenerateContentTypesError: {
|
||||
export const GenerateContentTypesError = {
|
||||
name: 'GenerateContentTypesError',
|
||||
title: 'Failed to generate content types.',
|
||||
message: (errorMessage: string) =>
|
||||
`\`astro sync\` command failed to generate content collection types: ${errorMessage}`,
|
||||
hint: 'Check your `src/content/config.*` file for typos.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @kind heading
|
||||
|
@ -968,9 +1020,10 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
*
|
||||
* If you can reliably cause this error to happen, we'd appreciate if you could [open an issue](https://astro.build/issues/)
|
||||
*/
|
||||
UnknownContentCollectionError: {
|
||||
export const UnknownContentCollectionError = {
|
||||
name: 'UnknownContentCollectionError',
|
||||
title: 'Unknown Content Collection Error.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message
|
||||
|
@ -984,7 +1037,8 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* You can check against the collection schema in your `src/content/config.*` file.
|
||||
* See the [Content collections documentation](https://docs.astro.build/en/guides/content-collections/) for more information.
|
||||
*/
|
||||
InvalidContentEntryFrontmatterError: {
|
||||
export const InvalidContentEntryFrontmatterError = {
|
||||
name: 'InvalidContentEntryFrontmatterError',
|
||||
title: 'Content entry frontmatter does not match schema.',
|
||||
message: (collection: string, entryId: string, error: ZodError) => {
|
||||
return [
|
||||
|
@ -995,7 +1049,7 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
].join('\n');
|
||||
},
|
||||
hint: 'See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message `COLLECTION_NAME` → `ENTRY_ID` has an invalid slug. `slug` must be a string.
|
||||
|
@ -1004,7 +1058,8 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* An entry in `src/content/` has an invalid `slug`. This field is reserved for generating entry slugs, and must be a string when present.
|
||||
*/
|
||||
InvalidContentEntrySlugError: {
|
||||
export const InvalidContentEntrySlugError = {
|
||||
name: 'InvalidContentEntrySlugError',
|
||||
title: 'Invalid content entry slug.',
|
||||
message: (collection: string, entryId: string) => {
|
||||
return `${String(collection)} → ${String(
|
||||
|
@ -1012,7 +1067,7 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
)} has an invalid slug. \`slug\` must be a string.`;
|
||||
},
|
||||
hint: 'See https://docs.astro.build/en/guides/content-collections/ for more on the `slug` field.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
@ -1020,12 +1075,13 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* A content collection schema should not contain the `slug` field. This is reserved by Astro for generating entry slugs. Remove `slug` from your schema. You can still use custom slugs in your frontmatter.
|
||||
*/
|
||||
ContentSchemaContainsSlugError: {
|
||||
export const ContentSchemaContainsSlugError = {
|
||||
name: 'ContentSchemaContainsSlugError',
|
||||
title: 'Content Schema should not contain `slug`.',
|
||||
message: (collectionName: string) =>
|
||||
`A content collection schema should not contain \`slug\` since it is reserved for slug generation. Remove this from your ${collectionName} collection schema.`,
|
||||
hint: 'See https://docs.astro.build/en/guides/content-collections/ for more on the `slug` field.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
|
||||
/**
|
||||
* @docs
|
||||
|
@ -1033,12 +1089,13 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* When querying a collection, ensure a collection directory with the requested name exists under `src/content/`.
|
||||
*/
|
||||
CollectionDoesNotExistError: {
|
||||
export const CollectionDoesNotExistError = {
|
||||
name: 'CollectionDoesNotExistError',
|
||||
title: 'Collection does not exist',
|
||||
message: (collectionName: string) =>
|
||||
`The collection **${collectionName}** does not exist. Ensure a collection directory with this name exists.`,
|
||||
hint: 'See https://docs.astro.build/en/guides/content-collections/ for more on creating collections.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message `COLLECTION_NAME` contains a mix of content and data entries. All entries must be of the same type.
|
||||
|
@ -1047,13 +1104,14 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* A content collection cannot contain a mix of content and data entries. You must store entries in separate collections by type.
|
||||
*/
|
||||
MixedContentDataCollectionError: {
|
||||
export const MixedContentDataCollectionError = {
|
||||
name: 'MixedContentDataCollectionError',
|
||||
title: 'Content and data cannot be in same collection.',
|
||||
message: (collection: string) => {
|
||||
return `**${collection}** contains a mix of content and data entries. All entries must be of the same type.`;
|
||||
},
|
||||
hint: 'Store data entries in a new collection separate from your content collection.',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message `COLLECTION_NAME` contains entries of type `ACTUAL_TYPE`, but is configured as a `EXPECTED_TYPE` collection.
|
||||
|
@ -1062,37 +1120,40 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* Content collections must contain entries of the type configured. Collections are `type: 'content'` by default. Try adding `type: 'data'` to your collection config for data collections.
|
||||
*/
|
||||
ContentCollectionTypeMismatchError: {
|
||||
export const ContentCollectionTypeMismatchError = {
|
||||
name: 'ContentCollectionTypeMismatchError',
|
||||
title: 'Collection contains entries of a different type.',
|
||||
message: (collection: string, expectedType: string, actualType: string) => {
|
||||
return `${collection} contains ${expectedType} entries, but is configured as a ${actualType} collection.`;
|
||||
},
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message `COLLECTION_ENTRY_NAME` failed to parse.
|
||||
* @description
|
||||
* Collection entries of `type: 'data'` must return an object with valid JSON (for `.json` entries) or YAML (for `.yaml` entries).
|
||||
*/
|
||||
DataCollectionEntryParseError: {
|
||||
export const DataCollectionEntryParseError = {
|
||||
name: 'DataCollectionEntryParseError',
|
||||
title: 'Data collection entry failed to parse.',
|
||||
message: (entryId: string, errorMessage: string) => {
|
||||
return `**${entryId}** failed to parse: ${errorMessage}`;
|
||||
},
|
||||
hint: 'Ensure your data entry is an object with valid JSON (for `.json` entries) or YAML (for `.yaml` entries).',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
/**
|
||||
* @docs
|
||||
* @message `COLLECTION_NAME` contains multiple entries with the same slug: `SLUG`. Slugs must be unique.
|
||||
* @description
|
||||
* Content collection entries must have unique slugs. Duplicates are often caused by the `slug` frontmatter property.
|
||||
*/
|
||||
DuplicateContentEntrySlugError: {
|
||||
export const DuplicateContentEntrySlugError = {
|
||||
name: 'DuplicateContentEntrySlugError',
|
||||
title: 'Duplicate content entry slug.',
|
||||
message: (collection: string, slug: string) => {
|
||||
return `**${collection}** contains multiple entries with the same slug: \`${slug}\`. Slugs must be unique.`;
|
||||
},
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
|
||||
/**
|
||||
* @docs
|
||||
|
@ -1101,15 +1162,14 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
* @description
|
||||
* `transform()` functions in your content config must return valid JSON, or data types compatible with the devalue library (including Dates, Maps, and Sets).
|
||||
*/
|
||||
UnsupportedConfigTransformError: {
|
||||
export const UnsupportedConfigTransformError = {
|
||||
name: 'UnsupportedConfigTransformError',
|
||||
title: 'Unsupported transform in content config.',
|
||||
message: (parseError: string) =>
|
||||
`\`transform()\` functions in your content config must return valid JSON, or data types compatible with the devalue library (including Dates, Maps, and Sets).\nFull error: ${parseError}`,
|
||||
hint: 'See the devalue library for all supported types: https://github.com/rich-harris/devalue',
|
||||
},
|
||||
} satisfies ErrorData;
|
||||
|
||||
// Generic catch-all - Only use this in extreme cases, like if there was a cosmic ray bit flip
|
||||
UnknownError: {
|
||||
title: 'Unknown Error.',
|
||||
},
|
||||
} as const satisfies Record<string, ErrorData>;
|
||||
export const UnknownError = { name: 'UnknownError', title: 'Unknown Error.' } satisfies ErrorData;
|
||||
// } as export const satisfies Record<string, ErrorData>;
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import type { ZodError } from 'zod';
|
||||
import { codeFrame } from './printer.js';
|
||||
import { getErrorDataByTitle } from './utils.js';
|
||||
|
||||
interface ErrorProperties {
|
||||
title?: string;
|
||||
name?: string;
|
||||
name: string;
|
||||
message?: string;
|
||||
location?: ErrorLocation;
|
||||
hint?: string;
|
||||
|
@ -43,16 +42,7 @@ export class AstroError extends Error {
|
|||
|
||||
const { name, title, message, stack, location, hint, frame } = props;
|
||||
this.title = title;
|
||||
|
||||
if (name && name !== 'Error') {
|
||||
this.name = name;
|
||||
} else if (this.title) {
|
||||
const errorData = getErrorDataByTitle(this.title)?.name;
|
||||
|
||||
if (errorData) {
|
||||
this.name = errorData;
|
||||
}
|
||||
}
|
||||
|
||||
if (message) this.message = message;
|
||||
// Only set this if we actually have a stack passed, otherwise uses Error's
|
||||
|
@ -92,8 +82,6 @@ export class CompilerError extends AstroError {
|
|||
|
||||
constructor(props: ErrorProperties, ...params: any) {
|
||||
super(props, ...params);
|
||||
|
||||
this.name = 'CompilerError';
|
||||
}
|
||||
|
||||
static is(err: unknown): err is CompilerError {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
export type { ErrorLocation, ErrorWithMetadata } from './errors';
|
||||
export { AstroErrorData } from './errors-data.js';
|
||||
export {
|
||||
AggregateError,
|
||||
AstroError,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import type { YAMLException } from 'js-yaml';
|
||||
import type { ErrorPayload as ViteErrorPayload } from 'vite';
|
||||
import type { SSRError } from '../../@types/astro.js';
|
||||
import { AstroErrorData, type ErrorData } from './errors-data.js';
|
||||
|
||||
/**
|
||||
* Get the line and character based on the offset
|
||||
|
@ -105,14 +104,3 @@ export function createSafeError(err: any): Error {
|
|||
export function normalizeLF(code: string) {
|
||||
return code.replace(/\r\n|\r(?!\n)|\n/g, '\n');
|
||||
}
|
||||
|
||||
export function getErrorDataByTitle(title: string) {
|
||||
const entry = Object.entries(AstroErrorData).find((data) => data[1].title === title);
|
||||
|
||||
if (entry) {
|
||||
return {
|
||||
name: entry[0],
|
||||
data: entry[1] as ErrorData,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,10 @@ import type {
|
|||
MiddlewareHandler,
|
||||
MiddlewareNext,
|
||||
} from '../../@types/astro';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import { warn } from '../logger/core.js';
|
||||
import type { Environment } from '../render';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
|
||||
/**
|
||||
* Utility function that is in charge of calling the middleware.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
|
||||
export function getRedirectLocationOrThrow(headers: Headers): string {
|
||||
let location = headers.get('location');
|
||||
|
|
|
@ -6,9 +6,10 @@ import type {
|
|||
SSRElement,
|
||||
SSRResult,
|
||||
} from '../../@types/astro';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import type { Environment } from './environment';
|
||||
import { getParamsAndProps } from './params-and-props.js';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
|
||||
const clientLocalsSymbol = Symbol.for('astro.locals');
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ import type {
|
|||
Props,
|
||||
RouteData,
|
||||
} from '../../@types/astro';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
|
||||
export function generatePaginateFunction(routeMatch: RouteData): PaginateFunction {
|
||||
return function paginateUtility(
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import type { ComponentInstance, Params, Props, RouteData } from '../../@types/astro';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import type { LogOptions } from '../logger/core.js';
|
||||
import { getParams } from '../routing/params.js';
|
||||
import { RouteCache, callGetStaticPaths, findPathItemByKey } from './route-cache.js';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
|
||||
interface GetParamsAndPropsOptions {
|
||||
mod: ComponentInstance;
|
||||
|
|
|
@ -11,8 +11,9 @@ import { renderSlotToString, type ComponentSlots } from '../../runtime/server/in
|
|||
import { renderJSX } from '../../runtime/server/jsx.js';
|
||||
import { chunkToString } from '../../runtime/server/render/index.js';
|
||||
import { AstroCookies } from '../cookies/index.js';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import { warn, type LogOptions } from '../logger/core.js';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
|
||||
const clientAddressSymbol = Symbol.for('astro.clientAddress');
|
||||
const responseSentSymbol = Symbol.for('astro.responseSent');
|
||||
|
|
|
@ -7,9 +7,9 @@ import type {
|
|||
RouteData,
|
||||
RuntimeMode,
|
||||
} from '../../@types/astro';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import { debug, warn, type LogOptions } from '../logger/core.js';
|
||||
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
import { stringifyParams } from '../routing/params.js';
|
||||
import { validateDynamicRouteModule, validateGetStaticPathsResult } from '../routing/validation.js';
|
||||
import { generatePaginateFunction } from './paginate.js';
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import type { ComponentInstance, GetStaticPathsResult, RouteData } from '../../@types/astro';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import { AstroError } from '../errors/index.js';
|
||||
import type { LogOptions } from '../logger/core';
|
||||
import { warn } from '../logger/core.js';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
|
||||
const VALID_PARAM_TYPES = ['string', 'number', 'undefined'];
|
||||
|
||||
|
|
|
@ -15,8 +15,9 @@ import { resolveConfig } from '../config/config.js';
|
|||
import { createNodeLogging } from '../config/logging.js';
|
||||
import { createSettings } from '../config/settings.js';
|
||||
import { createVite } from '../create-vite.js';
|
||||
import { AstroError, AstroErrorData, createSafeError, isAstroError } from '../errors/index.js';
|
||||
import { AstroError, createSafeError, isAstroError } from '../errors/index.js';
|
||||
import { info, type LogOptions } from '../logger/core.js';
|
||||
import * as AstroErrorData from '../errors/errors-data.js';
|
||||
|
||||
export type ProcessExit = 0 | 1;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import type { ZodError } from 'zod';
|
||||
import type { ErrorData } from '../core/errors/errors-data.js';
|
||||
import { AstroError, AstroErrorData, type ErrorWithMetadata } from '../core/errors/index.js';
|
||||
import { AstroError, type ErrorWithMetadata } from '../core/errors/index.js';
|
||||
import * as AstroErrorData from '../core/errors/errors-data.js';
|
||||
|
||||
const EVENT_ERROR = 'ASTRO_CLI_ERROR';
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import type { PluginObj } from '@babel/core';
|
||||
import * as t from '@babel/types';
|
||||
import { AstroErrorData } from '../core/errors/errors-data.js';
|
||||
import { AstroError } from '../core/errors/errors.js';
|
||||
import { resolvePath } from '../core/util.js';
|
||||
import type { PluginMetadata } from '../vite-plugin-astro/types';
|
||||
import * as AstroErrorData from '../core/errors/errors-data.js';
|
||||
|
||||
const ClientOnlyPlaceholder = 'astro-client-only';
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import type { PropagationHint } from '../../@types/astro';
|
||||
import { AstroError, AstroErrorData } from '../../core/errors/index.js';
|
||||
import { AstroError } from '../../core/errors/index.js';
|
||||
import type { AstroComponentFactory } from './render/index.js';
|
||||
import * as AstroErrorData from '../../core/errors/errors-data.js';
|
||||
|
||||
function validateArgs(args: unknown[]): args is Parameters<AstroComponentFactory> {
|
||||
if (args.length !== 3) return false;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import type { AstroGlobalPartial } from '../../@types/astro';
|
||||
import { ASTRO_VERSION } from '../../core/constants.js';
|
||||
import { AstroError, AstroErrorData } from '../../core/errors/index.js';
|
||||
import { AstroError } from '../../core/errors/index.js';
|
||||
import * as AstroErrorData from '../../core/errors/errors-data.js';
|
||||
|
||||
/** Create the Astro.glob() runtime function. */
|
||||
function createAstroGlobFn() {
|
||||
|
|
|
@ -4,10 +4,11 @@ import type {
|
|||
SSRLoadedRenderer,
|
||||
SSRResult,
|
||||
} from '../../@types/astro';
|
||||
import { AstroError, AstroErrorData } from '../../core/errors/index.js';
|
||||
import { AstroError } from '../../core/errors/index.js';
|
||||
import { escapeHTML } from './escape.js';
|
||||
import { serializeProps } from './serialize.js';
|
||||
import { serializeListValue } from './util.js';
|
||||
import * as AstroErrorData from '../../core/errors/errors-data.js';
|
||||
|
||||
export interface HydrationMetadata {
|
||||
directive: string;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import type { RouteData, SSRResult } from '../../../../@types/astro';
|
||||
import { AstroError, AstroErrorData } from '../../../../core/errors/index.js';
|
||||
import { AstroError } from '../../../../core/errors/index.js';
|
||||
import * as AstroErrorData from '../../../../core/errors/errors-data.js';
|
||||
import { chunkToByteArray, chunkToString, encoder, type RenderDestination } from '../common.js';
|
||||
import type { AstroComponentFactory } from './factory.js';
|
||||
import { isHeadAndContent } from './head-and-content.js';
|
||||
|
|
|
@ -5,8 +5,8 @@ import type {
|
|||
SSRResult,
|
||||
} from '../../../@types/astro';
|
||||
import type { RenderInstruction } from './types.js';
|
||||
|
||||
import { AstroError, AstroErrorData } from '../../../core/errors/index.js';
|
||||
import * as AstroErrorData from '../../../core/errors/errors-data.js';
|
||||
import { AstroError } from '../../../core/errors/index.js';
|
||||
import { HTMLBytes, markHTMLString } from '../escape.js';
|
||||
import { extractDirectives, generateHydrateScript } from '../hydration.js';
|
||||
import { serializeProps } from '../serialize.js';
|
||||
|
|
|
@ -18,6 +18,7 @@ export default function astroTransitions({ config }: { config: AstroConfig }): v
|
|||
if (id === resolvedVirtualModuleId) {
|
||||
if (!config.experimental.viewTransitions) {
|
||||
throw new AstroError({
|
||||
name: 'TransitionError',
|
||||
title: 'Experimental View Transitions not enabled',
|
||||
message: `View Transitions support is experimental. To enable update your config to include:
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ import type {
|
|||
SSRManifest,
|
||||
} from '../@types/astro';
|
||||
import { attachToResponse } from '../core/cookies/index.js';
|
||||
import { AstroErrorData, isAstroError } from '../core/errors/index.js';
|
||||
import { isAstroError } from '../core/errors/index.js';
|
||||
import * as AstroErrorData from '../core/errors/errors-data.js';
|
||||
import { warn } from '../core/logger/core.js';
|
||||
import { loadMiddleware } from '../core/middleware/loadMiddleware.js';
|
||||
import { isEndpointResult } from '../core/render/core.js';
|
||||
|
|
|
@ -10,7 +10,8 @@ import { fileURLToPath } from 'node:url';
|
|||
import type { Plugin } from 'vite';
|
||||
import { normalizePath } from 'vite';
|
||||
import type { AstroSettings } from '../@types/astro';
|
||||
import { AstroError, AstroErrorData, MarkdownError } from '../core/errors/index.js';
|
||||
import { AstroError, MarkdownError } from '../core/errors/index.js';
|
||||
import * as AstroErrorData from '../core/errors/errors-data.js';
|
||||
import type { LogOptions } from '../core/logger/core.js';
|
||||
import { warn } from '../core/logger/core.js';
|
||||
import { isMarkdownFile, rootRelativePath } from '../core/util.js';
|
||||
|
@ -27,6 +28,7 @@ function safeMatter(source: string, id: string) {
|
|||
return matter(source);
|
||||
} catch (err: any) {
|
||||
const markdownError = new MarkdownError({
|
||||
name: 'MarkdownError',
|
||||
message: err.message,
|
||||
stack: err.stack,
|
||||
location: {
|
||||
|
@ -61,6 +63,10 @@ const astroErrorModulePath = normalizePath(
|
|||
fileURLToPath(new URL('../core/errors/index.js', import.meta.url))
|
||||
);
|
||||
|
||||
const astroErrorDataModulePath = normalizePath(
|
||||
fileURLToPath(new URL('../core/errors/errors-data.js', import.meta.url))
|
||||
);
|
||||
|
||||
export default function markdown({ settings, logging }: AstroPluginOptions): Plugin {
|
||||
return {
|
||||
enforce: 'pre',
|
||||
|
@ -116,7 +122,8 @@ export default function markdown({ settings, logging }: AstroPluginOptions): Plu
|
|||
const code = escapeViteEnvReferences(`
|
||||
import { Fragment, jsx as h } from ${JSON.stringify(astroJsxRuntimeModulePath)};
|
||||
import { spreadAttributes } from ${JSON.stringify(astroServerRuntimeModulePath)};
|
||||
import { AstroError, AstroErrorData } from ${JSON.stringify(astroErrorModulePath)};
|
||||
import { AstroError } from ${JSON.stringify(astroErrorModulePath)};
|
||||
import { MarkdownImageNotFound } from ${JSON.stringify(astroErrorDataModulePath)};
|
||||
|
||||
${layout ? `import Layout from ${JSON.stringify(layout)};` : ''}
|
||||
${settings.config.experimental.assets ? 'import { getImage } from "astro:assets";' : ''}
|
||||
|
@ -133,8 +140,8 @@ export default function markdown({ settings, logging }: AstroPluginOptions): Plu
|
|||
async function getImageSafely(imageSrc, imagePath, resolvedImagePath) {
|
||||
if (!imageSrc) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.MarkdownImageNotFound,
|
||||
message: AstroErrorData.MarkdownImageNotFound.message(
|
||||
...MarkdownImageNotFound,
|
||||
message: MarkdownImageNotFound.message(
|
||||
imagePath,
|
||||
resolvedImagePath
|
||||
),
|
||||
|
|
|
@ -2,7 +2,8 @@ import type { AstroSettings } from '../@types/astro.js';
|
|||
import type { PageOptions } from '../vite-plugin-astro/types.js';
|
||||
|
||||
import * as eslexer from 'es-module-lexer';
|
||||
import { AstroError, AstroErrorData } from '../core/errors/index.js';
|
||||
import { AstroError } from '../core/errors/index.js';
|
||||
import * as AstroErrorData from '../core/errors/errors-data.js';
|
||||
|
||||
const BOOLEAN_EXPORTS = new Set(['prerender']);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import { AstroErrorData } from '../dist/core/errors/errors-data.js';
|
||||
import * as AstroErrorData from '../dist/core/errors/errors-data.js';
|
||||
import { AstroError } from '../dist/core/errors/errors.js';
|
||||
import * as events from '../dist/events/index.js';
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue