diff --git a/packages/astro/src/i18n/index.ts b/packages/astro/src/i18n/index.ts index 0d6be9e47be1..16df08b1c05f 100644 --- a/packages/astro/src/i18n/index.ts +++ b/packages/astro/src/i18n/index.ts @@ -157,7 +157,7 @@ export function getPathByLocale(locale: string, locales: Locales): string { } } } - throw new Error("Unreachable"); + throw new Unreachable(); } /** @@ -172,14 +172,14 @@ export function getLocaleByPath(path: string, locales: Locales): string { if (locale.path === path) { // the first code is the one that user usually wants const code = locale.codes.at(0); - if (code === undefined) throw new Error("Unreachable"); + if (code === undefined) throw new Unreachable(); return code; } } else if (locale === path) { return locale; } } - throw new Error("Unreachable"); + throw new Unreachable(); } /** @@ -241,3 +241,14 @@ function peekCodePathToUse(locales: Locales, locale: string): undefined | string return undefined; } + +class Unreachable extends Error { + constructor() { + super( + "Astro encountered an unexpected line of code.\n" + + "In most cases, this is not your fault, but a bug in astro code.\n" + + "If there isn't one already, please create an issue.\n" + + "https://astro.build/issues" + ); + } +}