From 4d543bec280f3b5e00e21727d78f25756a1ced75 Mon Sep 17 00:00:00 2001 From: HiDeoo Date: Wed, 11 Dec 2024 19:47:16 +0100 Subject: Improve error message with invalid configuration (#2656) --- .changeset/hip-roses-brush.md | 5 +++++ packages/starlight/index.ts | 15 +++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 .changeset/hip-roses-brush.md 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 { -- cgit