Skip to content

Commit

Permalink
refa (FileUploader.cs): trivial neutral refactoring to simplify FileU…
Browse files Browse the repository at this point in the history
…ploader_FatalErrorOccurred_() by employing a simple switch-expression (old was: if-conditions)
  • Loading branch information
ksidirop-laerdal committed Oct 18, 2024
1 parent 447f2c7 commit 9774f58
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,36 +418,27 @@ void FileUploader_FileUploadProgressPercentageAndDataThroughputChanged_(object s

void FileUploader_FatalErrorOccurred_(object sender, FatalErrorOccurredEventArgs ea)
{
var isAboutUnauthorized = ea.ErrorCode == EMcuMgrErrorCode.AccessDenied;
if (isAboutUnauthorized)
taskCompletionSource.TrySetException(ea.ErrorCode switch
{
taskCompletionSource.TrySetException(new UploadUnauthorizedException( //specific case
EMcuMgrErrorCode.Unknown => new UploadErroredOutRemoteFolderNotFoundException( //specific case
remoteFilePath: remoteFilePath,
mcuMgrErrorCode: ea.ErrorCode,
groupReturnCode: ea.GroupReturnCode,
nativeErrorMessage: ea.ErrorMessage
));
return;
}

var isAboutFolderNotExisting = ea.ErrorCode == EMcuMgrErrorCode.Unknown;
if (isAboutFolderNotExisting)
{
taskCompletionSource.TrySetException(new UploadErroredOutRemoteFolderNotFoundException( //specific case
),
EMcuMgrErrorCode.AccessDenied => new UploadUnauthorizedException( //specific case
remoteFilePath: remoteFilePath,
mcuMgrErrorCode: ea.ErrorCode,
groupReturnCode: ea.GroupReturnCode,
nativeErrorMessage: ea.ErrorMessage
));
return;
}

taskCompletionSource.TrySetException(new UploadErroredOutException( //generic
remoteFilePath: remoteFilePath,
mcuMgrErrorCode: ea.ErrorCode,
groupReturnCode: ea.GroupReturnCode,
nativeErrorMessage: ea.ErrorMessage
));
),
_ => new UploadErroredOutException( //generic
remoteFilePath: remoteFilePath,
mcuMgrErrorCode: ea.ErrorCode,
groupReturnCode: ea.GroupReturnCode,
nativeErrorMessage: ea.ErrorMessage
)
});
}
// ReSharper restore AccessToModifiedClosure
}
Expand Down

0 comments on commit 9774f58

Please sign in to comment.