FileSaver throws an exception when user click cancel on DialogWindow. #1040
Replies: 4 comments
-
The exception is expected. Probably error message should be different. We have just changed the implementation to avoid exception. It will be released later this week. |
Beta Was this translation helpful? Give feedback.
-
Great, thank you!! |
Beta Was this translation helpful? Give feedback.
-
@VladislavAntonyuk I think this behavior should be changed to support different status codes, e.g. public enum FileSaverStatus
{
Success, // file saved successfully
Error, // an error or exception occured
UserCancelled, // user manually cancelled the operation
} Then, the public record FileSaverResult(string? FilePath, Exception? exception, FileSaverStatus? Status)
{
// ...
} That way, we can interrogate the result, for example to display different messages to the user: var result = await _fileSaver.SaveAsync(filename, fileStream, CancellationToken.None);
if(!result.IsSuccessful)
{
switch(result.Status)
{
case Error:
await _dialogs.AlertAsync($"Failed to save file: { result.Exception }");
break;
case UserCancelled:
await _dialogs.AlertAsync("User cancelled");
break;
}
return;
}
await _dialogs.AlertAsync($"File saved successfully: { filename }"); or even simpler: var result = await _fileSaver.SaveAsync(filename, fileStream, CancellationToken.None);
switch(result.Status)
{
case Success:
await _dialogs.AlertAsync($"File saved successfully: { filename }");
break;
case Error:
await _dialogs.AlertAsync($"Failed to save file: { result.Exception }");
break;
case UserCancelled:
await _dialogs.AlertAsync("User cancelled");
break;
} |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to pick this topic up again? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Using the new FileSaver when user click Cancel, FileSaver throws an exception CommunityToolkit.Maui.Storage.FileSaveException: 'Path doesn't exist.' this is an error or an expected behavior?
On this repository, from Gerald Versluis, this situation was verified: https://github.com/jfversluis/MauiToolkitFileSaverSample.
Beta Was this translation helpful? Give feedback.
All reactions