diff options
author | HiDeoo | 2024-12-11 19:47:16 +0100 |
---|---|---|
committer | GitHub | 2024-12-11 19:47:16 +0100 |
commit | 4d543bec280f3b5e00e21727d78f25756a1ced75 (patch) | |
tree | 70c892e07b00d12b427d0939ed9b7caf4a02fdee | |
parent | 7f922e36ea8ed2462ff55e7917d3104d500490ad (diff) | |
download | IT.starlight-4d543bec280f3b5e00e21727d78f25756a1ced75.tar.gz IT.starlight-4d543bec280f3b5e00e21727d78f25756a1ced75.tar.bz2 IT.starlight-4d543bec280f3b5e00e21727d78f25756a1ced75.zip |
Improve error message with invalid configuration (#2656)
-rw-r--r-- | .changeset/hip-roses-brush.md | 5 | ||||
-rw-r--r-- | packages/starlight/index.ts | 15 |
2 files changed, 16 insertions, 4 deletions
diff --git a/.changeset/hip-roses-brush.md b/.changeset/hip-roses-brush.md new file mode 100644 index 00000000..d05453e2 --- /dev/null +++ b/.changeset/hip-roses-brush.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': patch +--- + +Improves error message when an invalid configuration or no configuration is provided to the Starlight integration. diff --git a/packages/starlight/index.ts b/packages/starlight/index.ts index 3859b630..c72d6e74 100644 --- a/packages/starlight/index.ts +++ b/packages/starlight/index.ts @@ -9,6 +9,7 @@ import mdx from '@astrojs/mdx'; import type { AstroIntegration } from 'astro'; +import { AstroError } from 'astro/errors'; import { spawn } from 'node:child_process'; import { dirname, relative } from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -27,10 +28,16 @@ import { import { processI18nConfig } from './utils/i18n'; import type { StarlightConfig } from './types'; -export default function StarlightIntegration({ - plugins, - ...opts -}: StarlightUserConfigWithPlugins): AstroIntegration { +export default function StarlightIntegration( + userOpts: StarlightUserConfigWithPlugins +): AstroIntegration { + if (typeof userOpts !== 'object' || userOpts === null || Array.isArray(userOpts)) + throw new AstroError( + 'Invalid config passed to starlight integration', + `The Starlight integration expects a configuration object with at least a \`title\` property.\n\n` + + `See more details in the [Starlight configuration reference](https://starlight.astro.build/reference/configuration/)\n` + ); + const { plugins, ...opts } = userOpts; let userConfig: StarlightConfig; let pluginTranslations: PluginTranslations = {}; return { |