Catching possible errors
This commit is contained in:
@@ -54,25 +54,6 @@ class CacheManager {
|
||||
return !indexedNote || indexedNote.mtime !== file.stat.mtime
|
||||
}
|
||||
|
||||
// private async _writeMinisearchIndex(minisearch: MiniSearch): Promise<void> {
|
||||
// if (!settings.persistCache) {
|
||||
// return
|
||||
// }
|
||||
// const json = JSON.stringify(minisearch)
|
||||
// const data = deflate(json)
|
||||
// await app.vault.adapter.writeBinary(minisearchCacheFilePath, data as any)
|
||||
// console.log('Omnisearch - Minisearch index saved on disk')
|
||||
// }
|
||||
//
|
||||
// private async _saveNotesCache() {
|
||||
// if (!settings.persistCache) {
|
||||
// return
|
||||
// }
|
||||
// const json = JSON.stringify(Array.from(this.documentsCache.entries()))
|
||||
// const data = deflate(json)
|
||||
// await app.vault.adapter.writeBinary(notesCacheFilePath, data as any)
|
||||
// console.log('Omnisearch - Notes cache saved on disk')
|
||||
// }
|
||||
}
|
||||
|
||||
export const cacheManager = new CacheManager()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { type CachedMetadata, Platform } from 'obsidian'
|
||||
import { type CachedMetadata, Notice, Platform } from 'obsidian'
|
||||
import type { SearchMatch } from '../globals'
|
||||
import {
|
||||
excerptAfter,
|
||||
@@ -78,6 +78,7 @@ export function loopIndex(index: number, nbItems: number): number {
|
||||
}
|
||||
|
||||
export function makeExcerpt(content: string, offset: number): string {
|
||||
try {
|
||||
const pos = offset ?? -1
|
||||
if (pos > -1) {
|
||||
const from = Math.max(0, pos - excerptBefore)
|
||||
@@ -88,6 +89,14 @@ export function makeExcerpt(content: string, offset: number): string {
|
||||
(to < content.length - 1 ? '…' : '')
|
||||
}
|
||||
return escapeHTML(content)
|
||||
} catch (e) {
|
||||
new Notice(
|
||||
'Omnisearch - Error while creating excerpt, see developer console'
|
||||
)
|
||||
console.error(`Omnisearch - Error while creating excerpt`)
|
||||
console.error(e)
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,14 +151,26 @@ export function getAliasesFromMetadata(
|
||||
metadata: CachedMetadata | null
|
||||
): string[] {
|
||||
const arrOrString = metadata?.frontmatter?.aliases ?? []
|
||||
try {
|
||||
return (
|
||||
Array.isArray(arrOrString) ? arrOrString : arrOrString.toString().split(',')
|
||||
Array.isArray(arrOrString)
|
||||
? arrOrString
|
||||
: arrOrString.toString().split(',')
|
||||
)
|
||||
.map(s => (s ? s.trim() : s))
|
||||
.filter(s => !!s)
|
||||
} catch (e) {
|
||||
new Notice(
|
||||
'Omnisearch - Error while getting aliases from file, see developer console'
|
||||
)
|
||||
console.error(`Omnisearch - Error while getting aliases from file`)
|
||||
console.error(e)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
export function getTagsFromMetadata(metadata: CachedMetadata | null): string[] {
|
||||
try {
|
||||
const arrOrString = metadata?.frontmatter?.tags ?? []
|
||||
const fromFrontMatter = (
|
||||
Array.isArray(arrOrString) ? arrOrString : arrOrString.split(',')
|
||||
@@ -161,6 +182,14 @@ export function getTagsFromMetadata(metadata: CachedMetadata | null): string[] {
|
||||
return [...fromFrontMatter, ...fromBody].map(t =>
|
||||
t[0] !== '#' ? '#' + t : t
|
||||
)
|
||||
} catch (e) {
|
||||
new Notice(
|
||||
'Omnisearch - Error while getting tags from file, see developer console'
|
||||
)
|
||||
console.error(`Omnisearch - Error while getting tags from file`)
|
||||
console.error(e)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user