#119 - Non-string value of sorting-spec: prevents the custom sorting from working w/o error message

- added a bit of defensive programming to fix the problem. The sorting spec with broken syntax is ignored (error is swallowed)
This commit is contained in:
SebastianMC 2023-12-14 17:28:22 +01:00
parent b5a9684f56
commit 124c851989
1 changed files with 2 additions and 1 deletions

View File

@ -154,7 +154,8 @@ export default class CustomSortPlugin extends Plugin {
aFile.path === `${this.settings.additionalSortspecFile}.md` // when user configured Inbox/sort aFile.path === `${this.settings.additionalSortspecFile}.md` // when user configured Inbox/sort
) { ) {
const sortingSpecTxt: string = mCache.getCache(aFile.path)?.frontmatter?.[SORTINGSPEC_YAML_KEY] const sortingSpecTxt: string = mCache.getCache(aFile.path)?.frontmatter?.[SORTINGSPEC_YAML_KEY]
if (sortingSpecTxt) { // Warning: newer Obsidian versions can return objects as well, hence the explicit check for string value
if (typeof sortingSpecTxt === 'string') {
anySortingSpecFound = true anySortingSpecFound = true
this.sortSpecCache = processor.parseSortSpecFromText( this.sortSpecCache = processor.parseSortSpecFromText(
sortingSpecTxt.split('\n'), sortingSpecTxt.split('\n'),