fix: create destination directory when moving a note - #135
Merged
Yakitrak merged 1 commit intoSep 1, 2026
Conversation
os.Rename fails with ENOENT when the destination directory does not exist, and Move mapped every rename error to NoteDoesNotExistError, so moving a note into a new folder reported "Cannot find note in vault" even though the source note was there. Create the intermediate directories before the rename, matching what create and daily already do for their note paths. The source is checked first so a genuinely missing note still reports NoteDoesNotExistError and does not leave an empty destination directory behind. Fixes Yakitrak#134
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
movenow creates any missing directories in the destination path before renaming the file, sonotesmd-cli move "Target Note" "newfolder/Target Note"works without runningmkdirfirst.(*Note).Movecalledos.Renameand mapped every error toNoteDoesNotExistError.os.Renamereturns ENOENT when the destination directory is missing, so the command printed "Cannot find note in vault" and blamed a source note that was sitting right there. The source is now checked before the directory is created, so a genuinely missing note still reportsNoteDoesNotExistErrorand does not leave an empty destination folder behind on its way to failing.Motivation and Context
Fixes #134.
That issue offered two options, better error text or creating the folder, and asked which you preferred. I went with creating it because
createanddailyalready do exactly this for their note paths (pkg/actions/create.go:43,pkg/actions/daily.go:47), which leftmoveas the odd one out. If you would rathermovestay conservative and just report the missing folder, say so and I will swap theos.MkdirAllfor a check on the parent directory plus a new error constant. It is a small change either way.Two subtests added to
TestMoveNote: one moves a note into a nested path that does not exist yet, one checks that a missing source note fails without creating the destination directory. The first fails on unpatchednote.gowith the exact error from the issue.The README line for
movegains the same sentence thecreatesection already has about intermediate directories.Checklist: