Skip to content

Commit

Permalink
Improve error message with invalid configuration (#2656)
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo authored Dec 11, 2024
1 parent 7f922e3 commit 4d543be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-roses-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': patch
---

Improves error message when an invalid configuration or no configuration is provided to the Starlight integration.
15 changes: 11 additions & 4 deletions packages/starlight/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand Down

0 comments on commit 4d543be

Please sign in to comment.