From ff4bdf31c8e5a71eda54f200c7578f646b85e537 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Thu, 22 Dec 2022 10:37:23 -0500 Subject: [PATCH] docs: Astro error for CLI errors --- packages/astro/src/cli/sync/index.ts | 19 +++++++-------- packages/astro/src/core/errors/errors-data.ts | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/packages/astro/src/cli/sync/index.ts b/packages/astro/src/cli/sync/index.ts index 25bdf92a6a8d..0e63fb02e74c 100644 --- a/packages/astro/src/cli/sync/index.ts +++ b/packages/astro/src/cli/sync/index.ts @@ -2,9 +2,10 @@ import type fsMod from 'node:fs'; import { performance } from 'node:perf_hooks'; import { dim } from 'kleur/colors'; import type { AstroSettings } from '../../@types/astro'; -import { error, info, LogOptions } from '../../core/logger/core.js'; +import { info, LogOptions } from '../../core/logger/core.js'; import { contentObservable, createContentTypesGenerator } from '../../content/index.js'; import { getTimeStat } from '../../core/build/util.js'; +import { AstroError, AstroErrorData } from '../../core/errors/index.js'; export async function sync( settings: AstroSettings, @@ -12,18 +13,16 @@ export async function sync( ): Promise<0 | 1> { const timerStart = performance.now(); - const contentTypesGenerator = await createContentTypesGenerator({ - contentConfigObserver: contentObservable({ status: 'loading' }), - logging, - fs, - settings, - }); - try { + const contentTypesGenerator = await createContentTypesGenerator({ + contentConfigObserver: contentObservable({ status: 'loading' }), + logging, + fs, + settings, + }); await contentTypesGenerator.init(); } catch (e) { - error(logging, 'content', 'Failed to generate content collection types: ' + e); - return 1; + throw new AstroError(AstroErrorData.GenerateContentTypesError); } info(logging, 'content', `Types generated ${dim(getTimeStat(timerStart, performance.now()))}`); diff --git a/packages/astro/src/core/errors/errors-data.ts b/packages/astro/src/core/errors/errors-data.ts index cc6e164c596e..57cf9f4d6831 100644 --- a/packages/astro/src/core/errors/errors-data.ts +++ b/packages/astro/src/core/errors/errors-data.ts @@ -552,6 +552,30 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati message: (legacyConfigKey: string) => `Legacy configuration detected: \`${legacyConfigKey}\`.`, hint: 'Please update your configuration to the new format.\nSee https://astro.build/config for more information.', }, + /** + * @docs + * @kind heading + * @name CLI Errors + */ + // CLI Errors - 8xxx + UnknownCLIError: { + title: 'Unknown CLI Error.', + code: 8000, + }, + /** + * @docs + * @description + * `astro sync` command failed to generate content collection types. + * @see + * - [Content collections documentation](https://docs.astro.build/en/guides/content-collections/) + */ + GenerateContentTypesError: { + title: 'Failed to generate content types.', + code: 8001, + message: '`astro sync` command failed to generate content collection types.', + hint: 'Check your `src/content/config.*` file for typos.', + }, + // Generic catch-all UnknownError: { title: 'Unknown Error.',