fix(commit.ts): update error handling to provide clearer feedback when commit message generation fails

feat(config.ts): add cleanUndefinedValues function to sanitize config values by converting 'undefined' and 'null' strings to actual values
refactor(config.ts): return cleaned config from getConfig function to ensure consistent data types
chore(migrations): log entriesToSet in migration to assist with debugging and tracking changes
This commit is contained in:
di-sukharev
2024-09-07 18:06:53 +03:00
parent 3493cbb42c
commit 119fedad53
3 changed files with 28 additions and 2 deletions

View File

@@ -183,7 +183,11 @@ ${chalk.grey('——————————————————')}`
}
}
} catch (error) {
commitGenerationSpinner.stop('📝 Commit message generated');
commitGenerationSpinner.stop(
`${chalk.red('✖')} Failed to generate the commit message`
);
console.log(error);
const err = error as Error;
outro(`${chalk.red('✖')} ${err?.message || err}`);

View File

@@ -462,6 +462,25 @@ interface GetConfigOptions {
setDefaultValues?: boolean;
}
const cleanUndefinedValues = (config: ConfigType) => {
return Object.fromEntries(
Object.entries(config).map(([_, v]) => {
try {
if (typeof v === 'string') {
if (v === 'undefined') return [_, undefined];
if (v === 'null') return [_, null];
const parsedValue = JSON.parse(v);
return [_, parsedValue];
}
return [_, v];
} catch (error) {
return [_, v];
}
})
);
};
export const getConfig = ({
envPath = defaultEnvPath,
globalPath = defaultConfigPath
@@ -471,7 +490,9 @@ export const getConfig = ({
const config = mergeConfigs(envConfig, globalConfig);
return config;
const cleanConfig = cleanUndefinedValues(config);
return cleanConfig as ConfigType;
};
export const setConfig = (

View File

@@ -15,6 +15,7 @@ export default function () {
}
if (entriesToSet.length > 0) setConfig(entriesToSet);
console.log(entriesToSet);
};
setDefaultConfigValues(getGlobalConfig());