Skip to content

Commit

Permalink
elaborate on Unreachable exception
Browse files Browse the repository at this point in the history
  • Loading branch information
lilnasy committed Jan 23, 2024
1 parent 1f75062 commit 4abc42e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/astro/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function getPathByLocale(locale: string, locales: Locales): string {
}
}
}
throw new Error("Unreachable");
throw new Unreachable();
}

/**
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -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"
);
}
}

0 comments on commit 4abc42e

Please sign in to comment.