refactor: enhance error handling and normalization across AI engines

This update introduces a centralized error handling mechanism for various AI engines, improving the consistency and clarity of error messages. The new `normalizeEngineError` function standardizes error responses, allowing for better user feedback and recovery suggestions. Additionally, specific error classes for insufficient credits, rate limits, and service availability have been implemented, along with user-friendly formatting for error messages. This refactor aims to enhance the overall user experience when interacting with the AI services.
This commit is contained in:
di-sukharev
2026-01-17 23:34:49 +03:00
parent 8b0ee25923
commit 5b241ed2d0
16 changed files with 1081 additions and 412 deletions

View File

@@ -11,6 +11,10 @@ import {
import chalk from 'chalk';
import { execa } from 'execa';
import { generateCommitMessageByDiff } from '../generateCommitMessageFromGitDiff';
import {
formatUserFriendlyError,
printFormattedError
} from '../utils/errors';
import {
assertGitRepo,
getChangedFiles,
@@ -211,10 +215,11 @@ ${chalk.grey('——————————————————')}`
`${chalk.red('✖')} Failed to generate the commit message`
);
console.log(error);
const errorConfig = getConfig();
const provider = errorConfig.OCO_AI_PROVIDER || 'openai';
const formatted = formatUserFriendlyError(error, provider);
outro(printFormattedError(formatted));
const err = error as Error;
outro(`${chalk.red('✖')} ${err?.message || err}`);
process.exit(1);
}
};