diff --git a/src/tools/vault-tools.ts b/src/tools/vault-tools.ts index d8a14a8..bf93000 100644 --- a/src/tools/vault-tools.ts +++ b/src/tools/vault-tools.ts @@ -448,11 +448,16 @@ export class VaultTools { }; } - // Path doesn't exist (shouldn't reach here) + // DEFENSIVE CODE - UNREACHABLE + // This code is unreachable because getAbstractFileByPath only returns TFile, TFolder, or null. + // All three cases are handled above (null at line 405, TFile at line 420, TFolder at line 436). + // TypeScript requires exhaustive handling, so this defensive return is included. + /* istanbul ignore next */ const result: StatResult = { path: normalizedPath, exists: false }; + /* istanbul ignore next */ return { content: [{ type: "text", @@ -520,11 +525,16 @@ export class VaultTools { }; } - // Path doesn't exist (shouldn't reach here) + // DEFENSIVE CODE - UNREACHABLE + // This code is unreachable because getAbstractFileByPath only returns TFile, TFolder, or null. + // All three cases are handled above (null at line 479, TFile at line 494, TFolder at line 509). + // TypeScript requires exhaustive handling, so this defensive return is included. + /* istanbul ignore next */ const result: ExistsResult = { path: normalizedPath, exists: false }; + /* istanbul ignore next */ return { content: [{ type: "text", diff --git a/tests/vault-tools.test.ts b/tests/vault-tools.test.ts index 8b8ee2f..b9dc00b 100644 --- a/tests/vault-tools.test.ts +++ b/tests/vault-tools.test.ts @@ -1303,4 +1303,18 @@ describe('VaultTools', () => { expect(parsed.matches[0].snippet).toContain('target'); }); }); + + describe('getFolderWaypoint - error handling', () => { + it('should handle file read errors gracefully', async () => { + const mockFile = createMockTFile('test.md'); + mockVault.getAbstractFileByPath = jest.fn().mockReturnValue(mockFile); + mockVault.read = jest.fn().mockRejectedValue(new Error('Permission denied')); + + const result = await vaultTools.getFolderWaypoint('test.md'); + + expect(result.isError).toBe(true); + expect(result.content[0].text).toContain('Get folder waypoint error'); + expect(result.content[0].text).toContain('Permission denied'); + }); + }); }); \ No newline at end of file