mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-02 00:09:48 +02:00
refactor: normalize error logging (#7370)
This commit is contained in:
parent
87c7639a52
commit
7c9892888d
10 changed files with 27 additions and 30 deletions
|
@ -10,6 +10,7 @@ import type {SwizzleComponentConfig, SwizzleConfig} from '@docusaurus/types';
|
|||
import type {SwizzlePlugin} from './common';
|
||||
import {SwizzleActions, SwizzleActionsStatuses} from './common';
|
||||
import {getPluginByThemeName} from './themes';
|
||||
import logger from '@docusaurus/logger';
|
||||
|
||||
function getModuleSwizzleConfig(
|
||||
swizzlePlugin: SwizzlePlugin,
|
||||
|
@ -103,12 +104,9 @@ export function getThemeSwizzleConfig(
|
|||
if (config) {
|
||||
try {
|
||||
return normalizeSwizzleConfig(config);
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
`Invalid Swizzle config for theme ${themeName}.\n${
|
||||
(e as Error).message
|
||||
}`,
|
||||
);
|
||||
} catch (err) {
|
||||
logger.error`Invalid Swizzle config for theme name=${themeName}.`;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
return FallbackSwizzleConfig;
|
||||
|
|
|
@ -343,17 +343,13 @@ describe('getHttpsConfig', () => {
|
|||
process.env.HTTPS = 'true';
|
||||
process.env.SSL_CRT_FILE = path.join(__dirname, '__fixtures__/host.crt');
|
||||
process.env.SSL_KEY_FILE = path.join(__dirname, '__fixtures__/invalid.key');
|
||||
await expect(getHttpsConfig()).rejects.toThrowError(
|
||||
/The certificate key .*[/\\]__fixtures__[/\\]invalid\.key is invalid/,
|
||||
);
|
||||
await expect(getHttpsConfig()).rejects.toThrowError();
|
||||
});
|
||||
|
||||
it('throws for invalid cert', async () => {
|
||||
process.env.HTTPS = 'true';
|
||||
process.env.SSL_CRT_FILE = path.join(__dirname, '__fixtures__/invalid.crt');
|
||||
process.env.SSL_KEY_FILE = path.join(__dirname, '__fixtures__/host.key');
|
||||
await expect(getHttpsConfig()).rejects.toThrowError(
|
||||
/The certificate .*[/\\]__fixtures__[/\\]invalid\.crt is invalid/,
|
||||
);
|
||||
await expect(getHttpsConfig()).rejects.toThrowError();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -291,20 +291,16 @@ function validateKeyAndCerts({
|
|||
// publicEncrypt will throw an error with an invalid cert
|
||||
encrypted = crypto.publicEncrypt(cert, Buffer.from('test'));
|
||||
} catch (err) {
|
||||
throw new Error(
|
||||
`The certificate ${crtFile} is invalid.
|
||||
${err}`,
|
||||
);
|
||||
logger.error`The certificate path=${crtFile} is invalid.`;
|
||||
throw err;
|
||||
}
|
||||
|
||||
try {
|
||||
// privateDecrypt will throw an error with an invalid key
|
||||
crypto.privateDecrypt(key, encrypted);
|
||||
} catch (err) {
|
||||
throw new Error(
|
||||
`The certificate key ${keyFile} is invalid.
|
||||
${err}`,
|
||||
);
|
||||
logger.error`The certificate key path=${keyFile} is invalid.`;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue