Skip to content

Commit

Permalink
feat!(error-silencing): add "Silence errors" function and add "Debug"…
Browse files Browse the repository at this point in the history
… toggle in the settings

Now, when "Silence errors" mode is enabled, errors will be debugged in the console and no notifications would appear.

Fix of #70
  • Loading branch information
Falcion committed Sep 21, 2024
1 parent 28166e3 commit 2a7ee5f
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 14 deletions.
58 changes: 44 additions & 14 deletions source/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ export default class UNITADE_PLUGIN extends Plugin {
return;
}
} catch (error) {
console.error('Error creating regular expression:', error);
if (!this.settings.silence_errors) {
console.error(error);
} else {
console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${error}`);
}
}
}
}
Expand Down Expand Up @@ -128,9 +132,13 @@ export default class UNITADE_PLUGIN extends Plugin {
this.settings.mobile_settings.extensions = __mb_settings.join(';');
}
} catch (err: any) {
new Notification('Error from UNITADE plugin:', { body: `Error with on-load registry of: ${filename.last()!}};` });
if (!this.settings.silence_errors) {
new Notification('Error from UNITADE plugin:', { body: `Error with on-load registry of: ${err}` });

console.error(err);
console.error(err);
} else {
console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${err}`);
}
}
}

Expand Down Expand Up @@ -163,9 +171,13 @@ export default class UNITADE_PLUGIN extends Plugin {
this.settings.mobile_settings.extensions = __mb_settings.join(';');
}
} catch (err: any) {
new Notification('Error from UNITADE plugin:', { body: `Error with on-load registry of: ${extensions}` });
if (!this.settings.silence_errors) {
new Notification('Error from UNITADE plugin:', { body: `Error with on-load registry of: ${extensions}` });

console.error(err);
console.error(err);
} else {
console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${err}`);
}
}
}
}
Expand Down Expand Up @@ -270,7 +282,13 @@ export default class UNITADE_PLUGIN extends Plugin {
try {
this.registerExtensions(['.md'], 'markdown');
} catch (err: any) {
console.error(err);
if (!this.settings.silence_errors) {
new Notification('Error from UNITADE plugin:', { body: err });

console.error(err);
} else {
console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${err}`);
}

this.settings.errors['markdown_override'] = `Error with reregistering extensions: ${err}`;
}
Expand Down Expand Up @@ -320,11 +338,15 @@ export default class UNITADE_PLUGIN extends Plugin {
return new UNITADE_VIEW(leaf, extension);
});
} catch (err: any) {
new Notification('Error from UNITADE plugin:', { body: `${err}` });

this.settings.errors[extension] = `Error from UNITADE plugin: ${err}`;

console.error(err);
if (!this.settings.silence_errors) {
new Notification('Error from UNITADE plugin:', { body: `${err}` });

console.error(err);
} else {
console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${err}`);
}
}
}
}
Expand Down Expand Up @@ -365,9 +387,13 @@ export default class UNITADE_PLUGIN extends Plugin {
_msg = `Could not register extension: ${filetype} to view as ${view}.\n${err}`;
}

new Notification('Error from UNITADE plugin:', { body: _msg });
if (!this.settings.silence_errors) {
new Notification('Error from UNITADE plugin:', { body: _msg });

console.error(_msg);
console.error(_msg);
} else {
console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${_msg}`);
}

this._settings.errors[filetype] = _msg;
}
Expand Down Expand Up @@ -425,11 +451,15 @@ export default class UNITADE_PLUGIN extends Plugin {
} catch (err: any) {
const _msg = `Couldn't unregistry extension: ${extension};`

new Notification('Error from UNITADE plugin:', { body: _msg });

this.settings.errors[extension] = _msg;

console.error(_msg);
if (!this.settings.silence_errors) {
new Notification('Error from UNITADE plugin:', { body: _msg });

console.error(_msg);
} else {
console.debug(`[UNITADE-ERROR]: Error is silenced, error: ${_msg}`);
}
}
}
}
Expand Down
45 changes: 45 additions & 0 deletions source/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface UNITADE_SETTINGS {
errors: Record<string, string>,

debug_mode: boolean,
silence_errors: boolean,
}

export const DEFAULT_SETTINGS: UNITADE_SETTINGS = {
Expand All @@ -84,6 +85,7 @@ export const DEFAULT_SETTINGS: UNITADE_SETTINGS = {
errors: {},

debug_mode: false,
silence_errors: false
}

export default class UNITADE_SETTINGS_TAB extends PluginSettingTab {
Expand Down Expand Up @@ -633,6 +635,49 @@ export default class UNITADE_SETTINGS_TAB extends PluginSettingTab {
groupExtInp.inputEl.style.width = '100%';
groupExtInp.inputEl.style.height = '48px';
groupExtInp.inputEl.style.minHeight = '36px';

containerEl.createEl('h3', { text: 'Additionals' });

new Setting(containerEl)
.setName('Debug mode:')
.setDesc('This mode starts output in application\'s console about actions you do.')
.setTooltip('Do not use this mode if you are not developer or familliar with console.')
.addToggle(toggle => {
toggle
.setValue(this.plugin.settings.debug_mode)
.onChange(async (value) => {
let next = {
...this.plugin.settings,
debug_mode: value,
};

await this.plugin.uptSettings(next);

this.__updateErrors();
});

return toggle;
});

new Setting(containerEl)
.setName('Silence errors:')
.setDesc('This mode silences every error and disables notifications: could help in case of error spamming.')
.addToggle(toggle => {
toggle
.setValue(this.plugin.settings.silence_errors)
.onChange(async (value) => {
let next = {
...this.plugin.settings,
silence_errors: value,
};

await this.plugin.uptSettings(next);

this.__updateErrors();
});

return toggle;
});
}

private __uptMbConfig(mbConfigInput: TextAreaComponent, mbConfigEnabled: boolean): void {
Expand Down

0 comments on commit 2a7ee5f

Please sign in to comment.