feat: improve config error message (#264)

This commit is contained in:
David 2024-09-15 10:53:39 -05:00 committed by GitHub
parent fcd9ffd34d
commit 23c23156e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -396,11 +396,18 @@ export class BaseClient {
>() {
const seyfertConfig = (BaseClient._seyfertCfWorkerConfig ||
(await this.options?.getRC?.()) ||
(await Promise.any(
['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts'].map(ext =>
magicImport(join(process.cwd(), `seyfert.config${ext}`)).then(x => x.default ?? x),
),
))) as T;
(
await Promise.any(
['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts'].map(ext =>
magicImport(join(process.cwd(), `seyfert.config${ext}`)).then(x => x.default ?? x),
),
)
).catch((e: AggregateError) => {
if (e.errors.every((err: Error) => err.stack?.includes('ERR_MODULE_NOT_FOUND'))) {
throw new Error('No seyfert.config file found');
}
throw e.errors.find((err: Error) => !err.stack?.includes('ERR_MODULE_NOT_FOUND')) ?? e.errors[0];
})) as T;
const { locations, debug, ...env } = seyfertConfig;