Skip to content

Commit

Permalink
docs: Astro error for CLI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Dec 22, 2022
1 parent db9586f commit ff4bdf3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/astro/src/cli/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@ 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,
{ logging, fs }: { logging: LogOptions; fs: typeof fsMod }
): 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()))}`);
Expand Down
24 changes: 24 additions & 0 deletions packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down

0 comments on commit ff4bdf3

Please sign in to comment.