fix(library): isolate per-note failures in candidate picker loop
This commit is contained in:
parent
d7162d3ac2
commit
4249952f0a
2 changed files with 38 additions and 4 deletions
|
|
@ -233,10 +233,16 @@ export class LibraryController {
|
||||||
skipped++;
|
skipped++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const content = await deps.readNote(entry.path);
|
try {
|
||||||
await deps.writeNote(entry.path, patchFrontmatter(content, candidate.patches, { defaultType: spec.itemType }));
|
const content = await deps.readNote(entry.path);
|
||||||
report.resolved.push(entry.path);
|
await deps.writeNote(entry.path, patchFrontmatter(content, candidate.patches, { defaultType: spec.itemType }));
|
||||||
picked++;
|
report.resolved.push(entry.path);
|
||||||
|
picked++;
|
||||||
|
} catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : String(e);
|
||||||
|
console.log(`[media-db-library] picker failed for ${entry.filename}: ${msg}`);
|
||||||
|
skipped++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
28
tests/library-controller-isolation.test.ts
Normal file
28
tests/library-controller-isolation.test.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { describe, expect, test } from 'bun:test';
|
||||||
|
|
||||||
|
// Test that verifies the try/catch wrapping is syntactically correct
|
||||||
|
// and the error handling path exists in LibraryController.resolveType
|
||||||
|
|
||||||
|
describe('LibraryController per-entry error isolation', () => {
|
||||||
|
test('try/catch present in resolveType for per-entry failures', async () => {
|
||||||
|
// Read the source file and verify try/catch is present
|
||||||
|
const srcText = (await Bun.file('packages/obsidian/src/library/LibraryController.ts').text());
|
||||||
|
|
||||||
|
// Verify the fix is in place: try block wrapping readNote/writeNote
|
||||||
|
expect(srcText).toContain('try {');
|
||||||
|
expect(srcText).toContain('const content = await deps.readNote(entry.path);');
|
||||||
|
expect(srcText).toContain('await deps.writeNote(entry.path');
|
||||||
|
expect(srcText).toContain('} catch (e) {');
|
||||||
|
expect(srcText).toContain('picker failed for');
|
||||||
|
expect(srcText).toContain('skipped++;');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('error logging includes filename and message', async () => {
|
||||||
|
const srcText = await Bun.file('packages/obsidian/src/library/LibraryController.ts').text();
|
||||||
|
|
||||||
|
// Verify error log includes entry filename
|
||||||
|
expect(srcText).toContain('picker failed for ${entry.filename}');
|
||||||
|
// Verify error message is captured
|
||||||
|
expect(srcText).toContain('e instanceof Error ? e.message : String(e)');
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue