Skip to content

Commit

Permalink
Improve message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Jun 20, 2024
1 parent c2bff0e commit fe67c34
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
7 changes: 4 additions & 3 deletions lib/messageLogging.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { actions } from "@neptune";

export const messageError = (message: string) => {
console.error(message);
actions.message.messageError({ message, category: "OTHER", severity: "ERROR" });
export const messageError = (message: string) => (error?: Error) => {
console.error(message, error);
const errMessage = error ? `${message} - ${error.message}` : message;
actions.message.messageError({ message: errMessage, category: "OTHER", severity: "ERROR" });
};
export const messageWarn = (message: string) => {
console.warn(message);
Expand Down
7 changes: 3 additions & 4 deletions plugins/LastFM/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const updateNowPlaying = async (playbackContext?: PlaybackContext) => {
const nowPlayingParams = await getTrackParams(currentTrack);
console.log("[last.fm] updatingNowPlaying", nowPlayingParams);
return LastFM.updateNowPlaying(nowPlayingParams)
.catch((err) => messageError(`last.fm - Failed to updateNowPlaying! ${err}`))
.catch(messageError(`last.fm - Failed to updateNowPlaying!`))
.then((res) => console.log("[last.fm] updatedNowPlaying", res));
};

Expand Down Expand Up @@ -56,14 +56,13 @@ const intercepters = [
getTrackParams(currentTrack).then((scrobbleParams) => {
console.log("[last.fm] scrobbling", scrobbleParams);
LastFM.scrobble(scrobbleParams)
.catch((err) => messageError(`last.fm - Failed to scrobble! ${err}`))
.catch(messageError(`last.fm - Failed to scrobble!`))
.then((res) => console.log("[last.fm] scrobbled", res));
});
} else {
const trackTitle = currentTrack.extTrackItem.trackItem()?.title;
const noScrobbleMessage = `skipped scrobbling ${trackTitle} - Listened for ${(totalPlayTime / 1000).toFixed(0)}s, need ${(minPlayTime / 1000).toFixed(0)}s`;
console.log(`[last.fm] ${noScrobbleMessage}`);
if (storage.displaySkippedScrobbles) messageInfo(`last.fm - ${noScrobbleMessage}`);
if (storage.displaySkippedScrobbles) messageInfo(`[last.fm] - ${noScrobbleMessage}`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/RealMAX/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "RealMAX",
"description": "Always ensure that the highest quality available of a track is played",
"description": "Always ensure that the highest quality available of a track is played",
"author": "Inrixia",
"main": "./src/index.js"
}
2 changes: 1 addition & 1 deletion plugins/Shazam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const handleDrop = async (event: DragEvent) => {
messageWarn(`No matches for ${file.name}`);
});
} catch (err) {
messageError(`Failed to recognize ${file.name}: ${(<Error>err).message}`);
messageError(`Failed to recognize ${file.name}`)(<Error>err);
}
}
};
Expand Down
5 changes: 1 addition & 4 deletions plugins/SongDownloader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ const downloadItems = (items: (TrackItem | VideoItem)[]) =>
prep();
for (const trackItem of trackItems) {
if (trackItem.id === undefined) continue;
await downloadTrack(trackItem, { trackId: trackItem.id, desiredQuality: storage.desiredDownloadQuality }, { onProgress }).catch((err) => {
messageError(err.message);
console.error(err);
});
await downloadTrack(trackItem, { trackId: trackItem.id, desiredQuality: storage.desiredDownloadQuality }, { onProgress }).catch(messageError("Error downloading track"));
}
clear();
});
Expand Down
10 changes: 6 additions & 4 deletions plugins/TidalTags/src/setFLACInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ export const setFLACInfo = async ([{ playbackContext }]: [{ playbackContext?: Pl
flacInfoElem.style.border = "solid 1px red";
const errorText = (<Error>err).message.substring(0, 64);
if (flacInfoElem.textContent.includes(Loading_Bitrate)) {
const errMsg = `Error Loading Bitrate - ${errorText}`;
const errHeader = `Error Loading Bitrate`;
const errMsg = `${errHeader} - ${errorText}`;
flacInfoElem.textContent = flacInfoElem.textContent?.replace(Loading_Bitrate, errMsg) ?? "";
messageError(errMsg);
messageError(errHeader)(<Error>err);
} else {
const errMsg = `Error Loading TrackInfo - ${errorText}`;
const errHeader = `Error Loading TrackInfo`;
const errMsg = `${errHeader} - ${errorText}`;
flacInfoElem.textContent = errMsg;
messageError(errMsg);
messageError(errHeader)(<Error>err);
}
}

Expand Down

0 comments on commit fe67c34

Please sign in to comment.