diff --git a/.changeset/breezy-worms-retire.md b/.changeset/breezy-worms-retire.md new file mode 100644 index 000000000000..e3b0c84492af --- /dev/null +++ b/.changeset/breezy-worms-retire.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Moved pagination error to AstroErrorData diff --git a/packages/astro/src/core/errors/errors-data.ts b/packages/astro/src/core/errors/errors-data.ts index ad71c4e0f69d..566ef100405d 100644 --- a/packages/astro/src/core/errors/errors-data.ts +++ b/packages/astro/src/core/errors/errors-data.ts @@ -429,6 +429,19 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati 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)}`.', }, + /** + * @docs + * @see + * - [Pagination](https://docs.astro.build/en/core-concepts/routing/#pagination) + * @description + * The page number parameter was not found in your filepath. + */ + PageNumberParamNotFound: { + title: 'Page number param not found.', + code: 3021, + message: (paramName: string) => `[paginate()] page number param \`${paramName}\` not found in your filepath.`, + hint: 'Rename your file to \`[page].astro\` or \`[...page].astro\`.' + }, // Vite Errors - 4xxx UnknownViteError: { title: 'Unknown Vite Error.', diff --git a/packages/astro/src/core/render/paginate.ts b/packages/astro/src/core/render/paginate.ts index 7bb5eca77a75..ddcca066f100 100644 --- a/packages/astro/src/core/render/paginate.ts +++ b/packages/astro/src/core/render/paginate.ts @@ -6,6 +6,7 @@ import { Props, RouteData, } from '../../@types/astro'; +import { AstroError, AstroErrorData } from '../errors/index.js'; export function generatePaginateFunction(routeMatch: RouteData): PaginateFunction { return function paginateUtility( @@ -23,9 +24,10 @@ export function generatePaginateFunction(routeMatch: RouteData): PaginateFunctio } else if (routeMatch.params.includes(`${paramName}`)) { includesFirstPageNumber = true; } else { - throw new Error( - `[paginate()] page number param \`${paramName}\` not found in your filepath.\nRename your file to \`[page].astro\` or \`[...page].astro\`.` - ); + throw new AstroError({ + ...AstroErrorData.PageNumberParamNotFound, + message: AstroErrorData.PageNumberParamNotFound.message(paramName), + }); } const lastPage = Math.max(1, Math.ceil(data.length / pageSize));