Skip to content

Commit

Permalink
fix(commit.ts): update error handling to provide clearer feedback whe…
Browse files Browse the repository at this point in the history
…n 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
  • Loading branch information
di-sukharev committed Sep 7, 2024
1 parent 3493cbb commit 119feda
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/commands/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
23 changes: 22 additions & 1 deletion src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = (
Expand Down
1 change: 1 addition & 0 deletions src/migrations/02_set_missing_default_values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function () {
}

if (entriesToSet.length > 0) setConfig(entriesToSet);
console.log(entriesToSet);
};

setDefaultConfigValues(getGlobalConfig());
Expand Down

0 comments on commit 119feda

Please sign in to comment.