Fixed some uncaught exceptions that were bugging me.
Canvas files can be empty. e.g. when the "Create new canvas" command is called:
immediately after the command:
a new empty .canvas file will be created
triggering the create event and causing a "Unexpected end of JSON input" error
when saving the file (<cmd/ctrl>+s or "Save current file" command):
{} will be written to the file
triggering a file modify event and causing a "canvas.nodes is not iterable" exception
Canvas file parsing errors
After "Canvas: Create new canvas" command:
```stacktrace
documents-repository.ts:53 Omnisearch: Error while adding "Untitled.canvas" to live cache SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at DocumentsRepository.getAndMapIndexedDocument (documents-repository.ts:100:27)
at async DocumentsRepository.addDocument (documents-repository.ts:43:19)
at async DocumentsRepository.getDocument (documents-repository.ts:69:5)
at async eval (search-engine.ts:82:25)
at async Promise.all (index 0)
at async SearchEngine.addFromPaths (search-engine.ts:80:7)
```
After saving the empty canvas file:
```stacktrace
documents-repository.ts:53 Omnisearch: Error while adding "Untitled.canvas" to live cache TypeError: canvas.nodes is not iterable
at DocumentsRepository.getAndMapIndexedDocument (documents-repository.ts:103:33)
at async DocumentsRepository.addDocument (documents-repository.ts:43:19)
at async NotesIndexer.refreshIndex (notes-indexer.ts:29:7)
```
When creating a directory in the vault, omnisearch attempts to index the directory as a document
on('create', (file) => any, ...) is triggered for both files and directories, so any triggers on create should handle the case where file is a TFolder.^1
Error on `mkdir foobar`
For example, after running `mkdir foobar` in the vault directory, the following exception is thrown:
```stacktrace
documents-repository.ts:53 Omnisearch: Error while adding "foobar" to live cache Error: Not a TFile: "foobar"
at DocumentsRepository.getAndMapIndexedDocument (documents-repository.ts:85:41)
at DocumentsRepository.addDocument (documents-repository.ts:43:30)
at DocumentsRepository.getDocument (documents-repository.ts:69:16)
at eval (search-engine.ts:82:63)
at Array.map ()
at SearchEngine.addFromPaths (search-engine.ts:81:15)
at eval (main.ts:114:26)
at e.tryTrigger (app.js:1:723011)
at e.trigger (app.js:1:722944)
at t.trigger (app.js:1:741049)
```
Fixed some uncaught exceptions that were bugging me.
create
event and causing a "Unexpected end of JSON input" error{}
will be written to the filemodify
event and causing a "canvas.nodes is not iterable" exceptionCanvas file parsing errors
After "Canvas: Create new canvas" command: ```stacktrace documents-repository.ts:53 Omnisearch: Error while adding "Untitled.canvas" to live cache SyntaxError: Unexpected end of JSON input at JSON.parse (on('create', (file) => any, ...)
is triggered for both files and directories, so any triggers oncreate
should handle the case wherefile
is aTFolder
.^1Error on `mkdir foobar`
For example, after running `mkdir foobar` in the vault directory, the following exception is thrown: ```stacktrace documents-repository.ts:53 Omnisearch: Error while adding "foobar" to live cache Error: Not a TFile: "foobar" at DocumentsRepository.getAndMapIndexedDocument (documents-repository.ts:85:41) at DocumentsRepository.addDocument (documents-repository.ts:43:30) at DocumentsRepository.getDocument (documents-repository.ts:69:16) at eval (search-engine.ts:82:63) at Array.map (