Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions src/cli/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import {
type ConfigError,
type EmbeddingError,
type IndexCorruptedError,
isMdmError,
type MdmError,
} from '../errors/index.js'
Expand Down Expand Up @@ -116,6 +117,29 @@ const formatConfigError = (e: ConfigError): FormattedError => {
}
}

const formatIndexReadError = (e: IndexCorruptedError): FormattedError => {
if (e.reason === 'VersionMismatch') {
return {
code: e.code,
message: 'Index update required',
details: e.details,
suggestions: ["Run 'mdm index' to rebuild it with this version of mdm"],
exitCode: EXIT_CODE.USER_ERROR,
}
}

return {
code: e.code,
message: 'Index cannot be read',
details: e.details ?? `Reason: ${e.reason}`,
suggestions: [
'Keep the current index for recovery and use a fresh MDM_HOME',
"Run 'mdm index <source-path>' to rebuild from source",
],
exitCode: EXIT_CODE.USER_ERROR,
}
}

// ============================================================================
// Error Formatter
// ============================================================================
Expand Down Expand Up @@ -245,15 +269,7 @@ export const formatError = (error: MdmError): FormattedError =>
suggestions: ["Run 'mdm index' first to build the index"] as const,
exitCode: EXIT_CODE.USER_ERROR,
}),
IndexCorruptedError: (e) => ({
code: e.code,
message: 'Index is corrupted',
details: e.details ?? `Corruption reason: ${e.reason}`,
suggestions: [
"Delete the .mdm folder and run 'mdm index' again",
] as const,
exitCode: EXIT_CODE.USER_ERROR,
}),
IndexCorruptedError: (e) => formatIndexReadError(e),
IndexBuildError: (e) => ({
code: e.code,
message: `Failed to build index for: ${e.path}`,
Expand Down