Skip to content

Commit

Permalink
Improve: Get more detailed logs
Browse files Browse the repository at this point in the history
  • Loading branch information
gokadzev committed Dec 28, 2023
1 parent d339a7a commit 9350f7e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
24 changes: 12 additions & 12 deletions lib/API/musify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ Future<List> fetchSongsList(String searchQuery) async {
final List<Video> searchResults = await yt.search.search(searchQuery);

return searchResults.map((video) => returnSongLayout(0, video)).toList();
} catch (e) {
logger.log('Error in fetchSongsList: $e');
} catch (e, stackTrace) {
logger.log('Error in fetchSongsList:$e\n$stackTrace');
return [];
}
}
Expand Down Expand Up @@ -91,8 +91,8 @@ Future<List> getRecommendedSongs() async {
playlistSongs.removeWhere((song) => !seenYtIds.add(song['ytid']));

return playlistSongs.take(15).toList();
} catch (e) {
logger.log('Error in getRecommendedSongs: $e');
} catch (e, stackTrace) {
logger.log('Error in getRecommendedSongs:$e\n$stackTrace');
return [];
}
}
Expand Down Expand Up @@ -293,8 +293,8 @@ Future<List<String>> getSearchSuggestions(String query) async {
// final suggestionStrings = suggestions.cast<String>().toList();
// return suggestionStrings;
// }
// } catch (e) {
// logger.log('Error in getSearchSuggestions: $e');
// } catch (e, stackTrace) {
// logger.log('Error in getSearchSuggestions:$e\n$stackTrace');
// }

// Built-in implementation:
Expand Down Expand Up @@ -427,8 +427,8 @@ Future<AudioOnlyStreamInfo> getSongManifest(String songId) async {
final manifest = await yt.videos.streamsClient.getManifest(songId);
final audioStream = manifest.audioOnly.withHighestBitrate();
return audioStream;
} catch (e) {
logger.log('Error while getting song streaming manifest: $e');
} catch (e, stackTrace) {
logger.log('Error while getting song streaming manifest:$e\n$stackTrace');
rethrow; // Rethrow the exception to allow the caller to handle it
}
}
Expand Down Expand Up @@ -456,8 +456,8 @@ Future<String> getSong(String songId, bool isLive) async {
} else {
return await getAudioUrl(songId, isQualityChanged, cacheKey);
}
} catch (e) {
logger.log('Error while getting song streaming URL: $e');
} catch (e, stackTrace) {
logger.log('Error while getting song streaming URL:$e\n$stackTrace');
rethrow;
}
}
Expand Down Expand Up @@ -509,8 +509,8 @@ Future<Map<String, dynamic>> getSongDetails(
try {
final song = await yt.videos.get(songId);
return returnSongLayout(songIndex, song);
} catch (e) {
logger.log('Error while getting song details: $e');
} catch (e, stackTrace) {
logger.log('Error while getting song details:$e\n$stackTrace');
rethrow;
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ class _MusifyState extends State<Musify> {
await rootBundle.loadString('assets/fonts/paytone/OFL.txt');
yield LicenseEntryWithLineBreaks(['google_fonts'], license1);
});
} catch (e) {
logger.log('License Registration Error: $e');
} catch (e, stackTrace) {
logger.log('License Registration Error:$e\n$stackTrace');
}
}

Expand Down Expand Up @@ -300,7 +300,7 @@ Future<void> initialisation() async {
progressBar: true,
tapOpensFile: true,
);
} catch (e) {
logger.log('Initialization Error: $e');
} catch (e, stackTrace) {
logger.log('Initialization Error:$e\n$stackTrace');
}
}
4 changes: 2 additions & 2 deletions lib/screens/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class _SearchPageState extends State<SearchPage> {

try {
_searchResult = await fetchSongsList(query);
} catch (e) {
logger.log('Error while searching online songs: $e');
} catch (e, stackTrace) {
logger.log('Error while searching online songs:$e\n$stackTrace');
}

if (_fetchingSongs.value) {
Expand Down
16 changes: 8 additions & 8 deletions lib/services/audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class MusifyAudioHandler extends BaseAudioHandler {
_updatePlaybackState();
try {
audioPlayer.setAudioSource(_playlist);
} catch (e) {
logger.log('Error in setNewPlaylist: $e');
} catch (e, stackTrace) {
logger.log('Error in setNewPlaylist:$e\n$stackTrace');
}

_initialize();
Expand Down Expand Up @@ -170,8 +170,8 @@ class MusifyAudioHandler extends BaseAudioHandler {
}
}
});
} catch (e) {
logger.log('Error initializing audio session: $e');
} catch (e, stackTrace) {
logger.log('Error initializing audio session:$e\n$stackTrace');
}
}

Expand Down Expand Up @@ -219,8 +219,8 @@ class MusifyAudioHandler extends BaseAudioHandler {
await checkIfSponsorBlockIsAvailable(song, songUrl);
}
await audioPlayer.play();
} catch (e) {
logger.log('Error playing song: $e');
} catch (e, stackTrace) {
logger.log('Error playing song:$e\n$stackTrace');
}
}

Expand Down Expand Up @@ -306,8 +306,8 @@ class MusifyAudioHandler extends BaseAudioHandler {
}

await audioPlayer.setAudioSource(_audioSource);
} catch (e) {
logger.log('Error checking sponsor block: $e');
} catch (e, stackTrace) {
logger.log('Error checking sponsor block:$e\n$stackTrace');
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/services/data_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ Future<String> backupData(BuildContext context) async {
await File(box.path!).copy(sourceFile.path);
}
return '${context.l10n!.backedupSuccess}!';
} catch (e) {
return '${context.l10n!.backupError}: $e';
} catch (e, stackTrace) {
return '${context.l10n!.backupError}: $e\n$stackTrace';
}
}

Expand All @@ -102,7 +102,7 @@ Future<String> restoreData(BuildContext context) async {
await sourceFile.copy(boxPath!);
}
return '${context.l10n!.restoredSuccess}!';
} catch (e) {
return '${context.l10n!.restoreError}: $e';
} catch (e, stackTrace) {
return '${context.l10n!.restoreError}: $e\n$stackTrace';
}
}
4 changes: 2 additions & 2 deletions lib/services/logger_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Logger {
} else {
return '${context.l10n!.copyLogsNoLogs}.';
}
} catch (e) {
log('Error copying logs: $e');
} catch (e, stackTrace) {
log('Error copying logs:$e\n$stackTrace');
return 'Error: $e';
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/services/update_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ Future<void> checkAppUpdates(BuildContext context) async {
'Fetch update API call returned status code ${response.statusCode}',
);
}
} catch (e) {
logger.log('Error in checkAppUpdates: $e');
} catch (e, stackTrace) {
logger.log('Error in checkAppUpdates:$e\n$stackTrace');
}
}

Expand All @@ -130,8 +130,8 @@ Future<void> downloadAppUpdates(Map<String, dynamic> map) async {
}
},
);
} catch (e) {
logger.log('Error in downloadAppUpdates: $e');
} catch (e, stackTrace) {
logger.log('Error in downloadAppUpdates:$e\n$stackTrace');
}
}

Expand Down Expand Up @@ -175,8 +175,8 @@ Future<void> checkNecessaryPermissions(BuildContext context) async {
await Permission.notification.request();
try {
await Permission.storage.request();
} catch (e) {
logger.log('Error while requesting permissions: $e');
} catch (e, stackTrace) {
logger.log('Error while requesting permissions:$e\n$stackTrace');
showToast(
context,
'${context.l10n!.errorWhileRequestingPerms} + $e',
Expand Down

0 comments on commit 9350f7e

Please sign in to comment.