Skip to content

Commit

Permalink
feat: add better error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
XeroxDev committed Feb 13, 2024
1 parent ad39dd8 commit 6408555
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/actions/default.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export abstract class DefaultAction<Instance> extends StreamDeckAction<
this.socket = YTMD.COMPANION.socketClient;
this.rest = YTMD.COMPANION.restClient;
console.info(`Initialized ${actionName}`);
plugin.logMessage(`Initialized ${actionName}`);
}

abstract onContextAppear(event: WillAppearEvent): void;
Expand Down
2 changes: 2 additions & 0 deletions src/actions/like-dislike.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ export class LikeDislikeAction extends DefaultAction<LikeDislikeAction> {
onKeypressUp(event: KeyUpEvent): void {
if (this.likeStatus === LikeStatus.LIKE) this.rest.toggleLike().catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while like toggle. like status: ${this.likeStatus}, event: ${JSON.stringify(event)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(event.context)
});
else if (this.likeStatus === LikeStatus.DISLIKE) this.rest.toggleDislike().catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while dislike toggle. like status: ${this.likeStatus}, event: ${JSON.stringify(event)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(event.context)
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/actions/mute.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class MuteAction extends DefaultAction<MuteAction> {

this.rest.setVolume(this.volume).catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while setting volume. volume: ${this.volume}, event: ${JSON.stringify(event)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(event.context)
});

Expand All @@ -71,6 +72,7 @@ export class MuteAction extends DefaultAction<MuteAction> {

this.rest.setVolume(this.volume).catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while setting volume. volume: ${this.volume}, event: ${JSON.stringify(event)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(event.context)
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/actions/next-prev-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ export class NextPrevAction extends DefaultAction<NextPrevAction> {
onKeypressUp(event: KeyUpEvent) {
if (this.nextOrPrev === 'NEXT') this.rest.next().catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while next. event: ${JSON.stringify(event)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(event.context)
});
else this.rest.previous().catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while previous. event: ${JSON.stringify(event)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(event.context)
})
}
Expand Down
4 changes: 4 additions & 0 deletions src/actions/play-pause.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class PlayPauseAction extends DefaultAction<PlayPauseAction> {
if (!settings?.action) {
this.rest.playPause().catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while playPause toggle. context: ${JSON.stringify(context)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(context)
})
return;
Expand All @@ -121,18 +122,21 @@ export class PlayPauseAction extends DefaultAction<PlayPauseAction> {
case 'PLAY':
this.rest.play().catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while play. context: ${JSON.stringify(context)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(context)
});
break;
case 'PAUSE':
this.rest.pause().catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while pause. context: ${JSON.stringify(context)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(context)
});
break;
default:
this.rest.playPause().catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while playPause toggle. context: ${JSON.stringify(context)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(context)
});
break;
Expand Down
3 changes: 1 addition & 2 deletions src/actions/repeat.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class RepeatAction extends DefaultAction<RepeatAction> {
found = {
context: event.context,
method: (state: StateOutput) => {
console.log("Repeat mode", state.player.queue?.repeatMode);
if (state.player.queue?.repeatMode === undefined || state.player.queue.repeatMode === null || state.player.queue.repeatMode === this.currentMode) {
return;
}
Expand Down Expand Up @@ -89,9 +88,9 @@ export class RepeatAction extends DefaultAction<RepeatAction> {
mode = RepeatMode.ONE;
break;
}
console.log("Repeat mode", mode);
this.rest.repeatMode(mode).catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while setting repeat mode. mode: ${mode}, event: ${JSON.stringify(event)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(event.context)
})
}
Expand Down
1 change: 1 addition & 0 deletions src/actions/shuffle.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class ShuffleAction extends DefaultAction<ShuffleAction> {
.then(() => this.plugin.showOk(event.context))
.catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while shuffle. event: ${JSON.stringify(event)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(event.context)
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/actions/song-info.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class SongInfoAction extends DefaultAction<SongInfoAction> {
context: event.context,
method: (state: StateOutput) => this.handleSongInfo(event, state).catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while executing handleSongInfo. state: ${JSON.stringify(state)}, event: ${JSON.stringify(event)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(event.context)
})
};
Expand Down Expand Up @@ -70,6 +71,7 @@ export class SongInfoAction extends DefaultAction<SongInfoAction> {
public onKeypressUp(event: KeyUpEvent): void {
this.rest.playPause().catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while playPause toggle (song info). event: ${JSON.stringify(event)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(event.context)
});
}
Expand Down
1 change: 1 addition & 0 deletions src/actions/vol-change.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class VolChangeAction extends DefaultAction<VolChangeAction> {
this.currentVolume = newVolume;
this.rest.setVolume(newVolume <= 0 ? 0 : newVolume >= 100 ? 100 : newVolume).catch(reason => {
console.error(reason);
this.plugin.logMessage(`Error while setting volume. volume: ${newVolume}, context: ${JSON.stringify(context)}, error: ${JSON.stringify(reason)}`);
this.plugin.showAlert(context)
});
await this.wait(500);
Expand Down
1 change: 1 addition & 0 deletions src/pis/play-pause.pi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class PlayPausePi extends PisAbstract {
}

private authErrorCatched(err: any) {
this.pi.logMessage(`Auth error: ${JSON.stringify(err)}`);
let msg = "";
if (err satisfies ErrorOutput) {
msg = err.message;
Expand Down
4 changes: 4 additions & 0 deletions src/ytmd-pi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ export class YTMDPi extends StreamDeckPropertyInspectorHandler {
private setupLocalization() {
this.fetchLocalizationFile(this.info.application.language ?? 'en', (b, s) => {
if (!b) {
this.logMessage(`Failed to load the localization file. Reason: ${s}. Using default language.`);
// try to load the default language
this.fetchLocalizationFile('en', (b2, s2) => {
if (!b2) {
this.logMessage(`Failed to load the default localization file. Reason: ${s2}.`);
}
this.localization = (s2 as LocalizationInterface).PI;
this.translateHtml();
});
Expand Down
1 change: 1 addition & 0 deletions src/ytmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class YTMD extends StreamDeckPluginHandler {
YTMD._COMPANION.socketClient.connect();
} catch (e) {
console.error(e);
this.logMessage(`Error while connecting. error: ${JSON.stringify(e)}`);
}
new PlayPauseAction(this, ActionTypes.PLAY_PAUSE);
new NextPrevAction(this, ActionTypes.NEXT_TRACK, 'NEXT');
Expand Down

0 comments on commit 6408555

Please sign in to comment.