kevboh / longform

A plugin for Obsidian that helps you write and edit novels, screenplays, and other long projects.
Other
664 stars 31 forks source link

Ignore hidden files on project load #146

Open PeteMichaud opened 1 year ago

PeteMichaud commented 1 year ago

Versions Longform version: 2.0.3 Obsidian version: 1.1.9 OS [e.g. macOS, Windows, iOS, Android]: MacOS Theme: Default Other plugins that you think might be relevant here: ? None ?

Describe the bug

Basically the system just doesn't work after updating to v2. I did a bunch of surgery when it first released and had some issues, but I set everything up as instructed and got it working in the sense that I could start a new longform project, see it in the pane, and re-add all my many files to it. But when I close and reopen Obsidian, my project is gone again, as if the folder and files don't exist at all (they do though). It works similarly if I start a dummy project and test files to it -- looks like it's working, then disappears when I close and open Obsidian. Maybe worth noting that on dummy projects when I've restarted Obsidian and found the project gone, I also find the dummy Index.md file doesn't contain any of the scene file names I'd expect in the relevant array? Just nothing there, even though the md files themselves are present as expected.

Here are a couple errors I've caught in the console either during initial plugin load or when switching to the project pane:

Uncaught (in promise) TypeError: The "path" argument must be of type string. Received null at __node_internal_captureLargerStackTrace (node:internal/errors:464:5) at new NodeError (node:internal/errors:371:5) at validateString (node:internal/validators:119:11) at Object.join (node:path:1172:7) at e.getFullRealPath (app.js:1:1093619) at e.getFullPath (app.js:1:1093542) at app.js:1:1085263 at n (app.js:1:1093945)

plugin:longform:35736 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'name') at eval (plugin:longform:35736:68) at Array.map () at StoreVaultSync.eval (plugin:longform:35736:22) at Generator.next () at fulfilled (plugin:longform:28:58)

It seems like it's having issues saving and loading settings data and that's causing it to error out before loading my project. It also seems to be having trouble persisting the scene list to the Index file? I'm not sure how to troubleshoot further. I left it until now basically because I saw other people having similar issues at the initial v2 launch and figured they'd get ironed out shortly. For me, that has not happened yet, and I'm not sure sure how to troubleshoot further.

Thanks for any help you can offer!

PeteMichaud commented 1 year ago

I tracked the second error down to: https://github.com/kevboh/longform/blob/7a5181f99a0b9b1b940df850401565ddc10a2877/src/model/store-vault-sync.ts#L403

looks like this.vault.getAbstractFileByPath(f) is returning null.

I'm in the process of trying to debug from within the obsidian browser inspector, and I'm noticing the code is a different version than what is linked above in the most recent master:

...
// Convert to indented scenes
const scenes = arraysToIndentedScenes(rawScenes);
const sceneFolder = (_d = longformEntry["sceneFolder"]) !== null && _d !== void 0 ? _d : "/";
const ignoredFiles = (_e = longformEntry["ignoredFiles"]) !== null && _e !== void 0 ? _e : [];
const normalizedSceneFolder = obsidian.normalizePath(`${fileWithMetadata.file.parent.path}/${sceneFolder}`);
const filenamesInSceneFolder = (yield this.vault.adapter.list(normalizedSceneFolder)).files
    .filter((f) => f !== fileWithMetadata.file.path && f.endsWith(".md"))
    .map((f) => this.vault.getAbstractFileByPath(f).name.slice(0, -3));
...

It's similar but not identical. I thought it could be a transpiling thing, but I noticed the sceneTemplate in github isn't present in the current release code I'm running. It may not actually matter for the bug that master is ahead of the release, just mentioning that in case.

PeteMichaud commented 1 year ago

Ok, I found the "file" that's returning null. It goes through a bunch of real files and has no issue, then it tries to use the filename ._Index.md which returns null and causes the error. No such file exists, I'm looking into why it has that in the list at all.

PeteMichaud commented 1 year ago

This file is very strange. I have my mac configured to show hidden files, but ._Index.md was not visible in Finder. It also wasn't visible in the terminal when I tried running ls but ls -al showed it. Its contents weren't plaintext. I don't know where the file came from, but that null error went away when I deleted it. Probably there should be a check to filter out files starting with . (ie hidden files)? It also seems to be that better error handling there would mean that if an individual files has a problem, it doesn't abort the entire plugin or project loading?

In any case, clearing that error produced a bunch more errors and the behavior is still similarly broken. I'll investigate further and see if they are really separate issues or what.

kevboh commented 1 year ago

Nice investigation. Ignoring hidden files is a great idea.

These sort of things are really difficult to debug on my end, but the easiest thing to do at this point might be to uninstall Longform entirely, format your projects in the new index format, and then reinstall. I say this because one possible cause is a borked migration, where it's trying to convert old projects that may have moved, etc. Starting with a fresh install means all you have to worry about is your index file formats across your vault—you could even use something like dataview to try and query them in-app, to audit manually.

Sorry I can't be of more help.

kevboh commented 1 year ago

See #151 for a bit of a better experience. Going to rename this ticket to concentrate on ignoring hidden files.