fix config.js

This commit is contained in:
xmz 2024-04-19 14:47:36 +08:00
parent c080837434
commit 110333f488

View File

@ -7,8 +7,7 @@ const inputSshKeyPath = 'SSH_PRIVATE_KEY_PATH';
const readConfig = (configPath) => { const readConfig = (configPath) => {
if (existsSync(configPath)) { if (existsSync(configPath)) {
const message = `⚠️ [FILE] ${configPath} Required file exist.`; const message = `⚠️ [FILE] ${configPath} Required file exist.`;
console.warn(message); throw new Error(message);
return null;
} }
try { try {
console.log(`[FILE] reading ${configPath} file ...`); console.log(`[FILE] reading ${configPath} file ...`);
@ -16,24 +15,21 @@ const readConfig = (configPath) => {
return JSON.parse(fileContents); return JSON.parse(fileContents);
} catch (error) { } catch (error) {
const message = `⚠️[FILE] reading file error. configPath: ${configPath}, message: ${error.message}`; const message = `⚠️[FILE] reading file error. configPath: ${configPath}, message: ${error.message}`;
console.warn(message); throw new Error(message);
return null;
} }
}; };
const readSshKey = (SshKeyPath) => { const readSshKey = (SshKeyPath) => {
if (existsSync(SshKeyPath)) { if (existsSync(SshKeyPath)) {
const message = `⚠️ [FILE] ${SshKeyPath} Required file exist.`; const message = `⚠️ [FILE] ${SshKeyPath} Required file exist.`;
console.warn(message); throw new Error(message);
return null;
} }
try { try {
console.log(`[FILE] reading ${SshKeyPath} file ...`); console.log(`[FILE] reading ${SshKeyPath} file ...`);
return readFileSync(SshKeyPath, 'utf8'); return readFileSync(SshKeyPath, 'utf8');
} catch (error) { } catch (error) {
const message = `⚠️[FILE] reading file error. configPath: ${SshKeyPath}, message: ${error.message}`; const message = `⚠️[FILE] reading file error. configPath: ${SshKeyPath}, message: ${error.message}`;
console.warn(message); throw new Error(message);
return '';
} }
}; };