Improve pending playlist sync error handling and logging
- Add detailed logging for each local track being added - Catch and re-throw errors when adding local tracks fails - Prevent marking playlist as synced if any operation fails - Show error details in toast notifications - Ensures playlists will retry sync on next online transition if failed - Fixes playlists being marked synced without local tracks added
This commit is contained in:
1 parent
f4867deeb0
commit
239a1f54a9
1 file changed
+16
-7
@@ -464,22 +464,31 @@ export async function syncPendingPlaylists(): Promise<void> {
|
|||||||
if (playlist.localTrackIds.length > 0) {
|
if (playlist.localTrackIds.length > 0) {
|
||||||
console.log(`[Offline] Adding ${playlist.localTrackIds.length} local tracks`);
|
console.log(`[Offline] Adding ${playlist.localTrackIds.length} local tracks`);
|
||||||
for (let i = 0; i < playlist.localTrackIds.length; i++) {
|
for (let i = 0; i < playlist.localTrackIds.length; i++) {
|
||||||
await invoke('playlist_add_local_track', {
|
console.log(`[Offline] Adding local track ${playlist.localTrackIds[i]} at position ${playlist.trackIds.length + i}`);
|
||||||
playlistId: qobuzPlaylistId,
|
try {
|
||||||
localTrackId: playlist.localTrackIds[i],
|
await invoke('playlist_add_local_track', {
|
||||||
position: playlist.trackIds.length + i // Position after Qobuz tracks
|
playlistId: qobuzPlaylistId,
|
||||||
});
|
localTrackId: playlist.localTrackIds[i],
|
||||||
|
position: playlist.trackIds.length + i // Position after Qobuz tracks
|
||||||
|
});
|
||||||
|
console.log(`[Offline] Successfully added local track ${playlist.localTrackIds[i]}`);
|
||||||
|
} catch (localTrackErr) {
|
||||||
|
console.error(`[Offline] Failed to add local track ${playlist.localTrackIds[i]}:`, localTrackErr);
|
||||||
|
// Re-throw to prevent marking as synced
|
||||||
|
throw new Error(`Failed to add local track: ${localTrackErr}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark as synced
|
// Mark as synced ONLY if everything succeeded
|
||||||
await markPendingPlaylistSynced(playlist.id, qobuzPlaylistId);
|
await markPendingPlaylistSynced(playlist.id, qobuzPlaylistId);
|
||||||
console.log(`[Offline] Successfully synced playlist: ${playlist.name}`);
|
console.log(`[Offline] Successfully synced playlist: ${playlist.name}`);
|
||||||
|
|
||||||
showToast(`Synced playlist "${playlist.name}"`, 'success');
|
showToast(`Synced playlist "${playlist.name}"`, 'success');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`[Offline] Failed to sync playlist "${playlist.name}":`, err);
|
console.error(`[Offline] Failed to sync playlist "${playlist.name}":`, err);
|
||||||
showToast(`Failed to sync playlist "${playlist.name}"`, 'error');
|
showToast(`Failed to sync playlist "${playlist.name}": ${err}`, 'error');
|
||||||
|
// Don't mark as synced if there was an error - will retry on next online transition
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user