-
-
Notifications
You must be signed in to change notification settings - Fork 4
Error handling
Error handling in UNITADE has it's own unique style and philosophy which can be called "shut up and just work" (or just "SAJW"), because of entire complexity of Obsidian's codebase and unknown private parts of it's API, where most required parts for the plugin are privated and only accessed in runtime and didn't provide any documentation with them, plugin can and need to message about errors in its own ways and categories.
Globally, errors thrown by UNITADE can be categorized in 3 groups:
-
Local errors thrown by processing codebase (or "processing errors"), example of this error is:
const _mask = mask.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); try { const regex = new RegExp(_mask); if (regex.test(file.name)) { return; } } catch (error) { if (!this.settings.silence_errors) { console.error(error); } else { console.debug(`[UNITADE-ERROR]: ERROR IS SILENCED, ERROR: ${error}`); } }
This error is thrown, when "ignore mode" is enabled by plugin and when given regular expression is incorrect either can't be parsed by TypeScript language, this error occurs by processing data or "dealing" with basic functionality.
-
Types and views related errors (or "typeview errors"), example of this error is popular and even occured in issue #70:
private __tryApply(filetype: string, view: string): void { if (!this.settings.markdown_overcharge && ['md', 'mdown', 'markdown'].includes(filetype)) return; /**@ts-expect-error: not part of public API, accessing through runtime. */ if (this.app.viewRegistry.isExtensionRegistered(filetype)) return; try { this.registerExtensions([filetype], view); } catch (err: any) { /**@ts-expect-error: not part of public API, accessing through runtime. */ const curr: string = this.app.viewRegistry.getTypeByExtension(filetype); let _msg: string; if (curr) { _msg = formatString(this.locale.getLocaleItem('ERROR_REGISTRY_EXTENSION')[0]!, filetype, view); } else { _msg = formatString(this.locale.getLocaleItem('ERROR_REGISTRY_EXTENSION')[1]!, filetype, view, err); } if (!this.settings.silence_errors) { new Notification(this.locale.getLocaleItem('ERROR_COMMON_MESSAGE')[0]!, { body: _msg }); console.error(_msg); } else { console.debug(`[UNITADE-ERROR]: ERROR IS SILENCED, ERROR: ${_msg}`); } this._settings.errors[filetype] = _msg; } }
This method is a corresponsive one for reading basic extensions and parsing them into the Obsidian Vault, this is so called "common settings" extensions which are popular with throwing exceptions not only in UI of the plugin, but for the system also, more about it read at issue #70.
-
Errors caused by API of the plugin or in the process of it's work (or "hidden errors"), this errors do not have any direct example, because most of the time when they appear Obsidian or UNITADE are crashing/not launching correctly.
Note
You can silence errors, more about it in the specified article.