Skip to content

Commit

Permalink
Emit console.trace instead of throwing errors for non-critical stuff
Browse files Browse the repository at this point in the history
Fixes #7

The issue is here that a promise is usually expected, so I cannot just return
Promise.ject() with an empty error, because this also results in a red error
for the promise (with the worse error message "undefined").

Thus I've just made it to return a successful promise or undefined.

I've also changed the similar uncritical error when tips should be shown
according to gobal randomize, but no tip could be shown due to other factors,
so there is no tip to be shown.

Console.trace is BTW well-supported across browsers:
https://developer.mozilla.org/en-US/docs/Web/API/console/trace#browser_compatibility
  • Loading branch information
rugk committed Aug 22, 2022
1 parent 0eaaf04 commit 6af2eef
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions RandomTips.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ export function setContext(newContext) {
export async function showRandomTip() {
// only try to select tip, if one is even available
if (tips.length === 0) {
console.info("no tips to show available anymore");
return Promise.reject(new Error("no tips to show available anymore"));
console.trace("no tips to show available anymore");
return;
}

// randomly select element
Expand All @@ -322,15 +322,15 @@ export async function showRandomTip() {
* Shows the random tip only randomly so the user is not annoyed.
*
* @public
* @returns {Promise}
* @returns {Promise | undefined}
*/
export function showRandomTipIfWanted() {
saveConfig();

// randomize tip showing in general
if (!randomizePassed(GLOBAL_RANDOMIZE)) {
console.info("show no random tip, because randomize did not pass");
return Promise.reject(new Error("show no random tip, because randomize did not pass"));
console.trace("show no random tip, because randomize did not pass");
return;
}

return showRandomTip();
Expand Down

0 comments on commit 6af2eef

Please sign in to comment.