mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-04-20 03:02:51 -04:00
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:
@@ -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}`);
|
||||
|
||||
@@ -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 = (
|
||||
|
||||
@@ -15,6 +15,7 @@ export default function () {
|
||||
}
|
||||
|
||||
if (entriesToSet.length > 0) setConfig(entriesToSet);
|
||||
console.log(entriesToSet);
|
||||
};
|
||||
|
||||
setDefaultConfigValues(getGlobalConfig());
|
||||
|
||||
Reference in New Issue
Block a user