From cc2b8085f5e314f0de7099ee50a1c30214bf755f Mon Sep 17 00:00:00 2001 From: abraunegg Date: Fri, 13 Nov 2020 05:42:24 +1100 Subject: [PATCH] Update error catching and handling * Update error catching and handling --- src/onedrive.d | 12 +++++++++++- src/sync.d | 7 ++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/onedrive.d b/src/onedrive.d index 0d8d5157..467cfbe8 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -493,8 +493,17 @@ final class OneDriveApi { checkAccessTokenExpired(); scope(failure) { - if (exists(saveToPath)) remove(saveToPath); + if (exists(saveToPath)) { + // try and remove the file, catch error + try { + remove(saveToPath); + } catch (FileException e) { + // display the error message + displayFileSystemErrorMessage(e.msg); + } + } } + // Create the directory string newPath = dirName(saveToPath); mkdirRecurse(newPath); @@ -803,6 +812,7 @@ final class OneDriveApi { // Threshold for displaying download bar long thresholdFileSize = 4 * 2^^20; // 4 MiB + // open file as write in binary mode auto file = File(filename, "wb"); // function scopes diff --git a/src/sync.d b/src/sync.d index 446b47a2..012600dc 100644 --- a/src/sync.d +++ b/src/sync.d @@ -2565,7 +2565,6 @@ final class SyncEngine log.vdebug("onedrive.downloadById(item.driveId, item.id, path, fileSize); generated a OneDriveException"); // 408 = Request Time Out // 429 = Too Many Requests - need to delay - if (e.httpStatusCode == 408) { // 408 error handling - request time out // https://github.com/abraunegg/onedrive/issues/694 @@ -2637,6 +2636,12 @@ final class SyncEngine } } } + } catch (FileException e) { + // There was a file system error + // display the error message + displayFileSystemErrorMessage(e.msg); + downloadFailed = true; + return; } catch (std.exception.ErrnoException e) { // There was a file system error // display the error message