From 89bae42d0b637ca63944c298633167f4d4e31347 Mon Sep 17 00:00:00 2001 From: Moy Date: Fri, 3 Jul 2026 20:36:12 +0800 Subject: [PATCH] feat: throw FolderNotesApiAlreadyFolderNoteError if note is already a folder note --- src/api.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/api.ts b/src/api.ts index 050d96f..6cfb76b 100644 --- a/src/api.ts +++ b/src/api.ts @@ -39,6 +39,8 @@ export interface FolderNotesApi { * Converts an existing note into the folder note for its parent folder. * Throws FolderNotesApiPathError if the path does not point to a note * inside a non-root folder. + * Throws FolderNotesApiAlreadyFolderNoteError if the note is already + * a folder note (e.g. aa/aa.md). */ convertNoteToFolderNote(notePath: string, options?: ConvertNoteToFolderNoteOptions): Promise; } @@ -53,6 +55,13 @@ export class FolderNotesApiPathError extends Error { } } +export class FolderNotesApiAlreadyFolderNoteError extends Error { + constructor(readonly notePath: string) { + super(`Note is already a folder note: ${notePath}`); + this.name = 'FolderNotesApiAlreadyFolderNoteError'; + } +} + export function getApi(plugin: FolderNotesPlugin): FolderNotesApi { return { version: API_VERSION, @@ -85,6 +94,11 @@ async function convertNoteToFolderNote( throw new FolderNotesApiPathError(`Note must be inside a non-root folder: ${notePath}`, notePath); } + // Guard: already a folder note (e.g. aa/aa.md) + if (getFolderNote(plugin, parentFolder.path) === file) { + throw new FolderNotesApiAlreadyFolderNoteError(notePath); + } + // Build the new folder path: sibling folder named after the note's basename const newFolderPath = parentFolder.path === '' ? file.basename