Skip to content

Commit 5a4973f

Browse files
committed
Fix indexing failure tracking
1 parent ebdbacb commit 5a4973f

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

src/cli.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ export async function main() {
3434
const config = await loadConfig({ verbose: options.verbose });
3535
console.log(`Indexing ${paths.length} ${paths.length === 1 ? 'directory' : 'directories'}: ${paths.join(', ')}`);
3636
const result = await indexDirectories(paths, config);
37-
console.log(`Indexed ${result.indexed} files, skipped ${result.skipped} files, ${result.errors.length} errors`);
38-
if (result.errors.length > 0 && config.verbose) {
39-
console.log('Errors:', result.errors);
37+
console.log(`Indexed ${result.indexed} files, skipped ${result.skipped} files, ${result.failed} failed`);
38+
if (result.errors.length > 0) {
39+
console.log(`Errors: [`);
40+
result.errors.forEach(error => {
41+
console.log(` '${error}'`);
42+
});
43+
console.log(`]`);
4044
}
4145
} catch (error) {
4246
console.error('Error indexing directories:', error);

src/indexing.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface ScanOptions {
2222
export interface IndexResult {
2323
indexed: number;
2424
skipped: number;
25+
failed: number;
2526
errors: string[];
2627
}
2728

@@ -164,6 +165,7 @@ async function shouldReprocessFile(filePath: string, existingRecord: FileRecord,
164165
export async function indexDirectories(paths: string[], config: Config): Promise<IndexResult> {
165166
let indexed = 0;
166167
let skipped = 0;
168+
let failed = 0;
167169
const errors: string[] = [];
168170

169171
const scanOptions: ScanOptions = {
@@ -253,7 +255,12 @@ export async function indexDirectories(paths: string[], config: Config): Promise
253255
} catch (error) {
254256
const errorMessage = error instanceof Error ? error.message : String(error);
255257
const causeMessage = error instanceof Error && error.cause ? `: ${(error.cause as Error).message}` : '';
256-
errors.push(`Failed to process ${file.path}: ${errorMessage}${causeMessage}`);
258+
const fullError = `Failed to process ${file.path}: ${errorMessage}${causeMessage}`;
259+
errors.push(fullError);
260+
failed++;
261+
262+
// Print error immediately during processing (not just in verbose mode)
263+
console.error(`❌ ${fullError}`);
257264
}
258265
}
259266

@@ -269,5 +276,5 @@ export async function indexDirectories(paths: string[], config: Config): Promise
269276
}
270277
}
271278

272-
return { indexed, skipped, errors };
279+
return { indexed, skipped, failed, errors };
273280
}

src/mcp-handlers.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,21 @@ export async function handleIndexTool(args: unknown, config: Config): Promise<Ca
6666
const paths = args.directory_path.split(',').map((p: string) => p.trim());
6767
const result = await indexDirectories(paths, config);
6868

69+
let responseText = `Indexed ${result.indexed} files, skipped ${result.skipped} files, ${result.failed} failed`;
70+
71+
if (result.errors.length > 0) {
72+
responseText += `\nErrors: [\n`;
73+
result.errors.forEach(error => {
74+
responseText += ` '${error}'\n`;
75+
});
76+
responseText += `]`;
77+
}
78+
6979
return {
7080
content: [
7181
{
7282
type: 'text',
73-
text: `Indexed ${result.indexed} files, skipped ${result.skipped} files, ${result.errors.length} errors`
83+
text: responseText
7484
}
7585
]
7686
};

tests/mcp-handlers.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe('MCP Handlers Unit Tests', () => {
3737
vi.mocked(indexDirectories).mockResolvedValue({
3838
indexed: 5,
3939
skipped: 2,
40+
failed: 1,
4041
errors: ['error1']
4142
});
4243

@@ -49,7 +50,10 @@ describe('MCP Handlers Unit Tests', () => {
4950
expect(result).toEqual({
5051
content: [{
5152
type: 'text',
52-
text: 'Indexed 5 files, skipped 2 files, 1 errors'
53+
text: `Indexed 5 files, skipped 2 files, 1 failed
54+
Errors: [
55+
'error1'
56+
]`
5357
}]
5458
});
5559
});

0 commit comments

Comments
 (0)