From 89d891918c19a68a84f33ae637f8dad8bdaf4a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Tue, 15 Feb 2022 21:26:13 +0100 Subject: [PATCH] Better error messages --- .../FileTime.Avalonia.csproj | 2 +- .../Services/CommandHandlerService.cs | 2 +- .../Services/KeyInputHandlerService.cs | 23 ++++++++++++++++--- .../Services/StatePersistenceService.cs | 2 +- .../Persistence/PersistenceService.cs | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/GuiApp/FileTime.Avalonia/FileTime.Avalonia.csproj b/src/GuiApp/FileTime.Avalonia/FileTime.Avalonia.csproj index 08141c0..3d472b5 100644 --- a/src/GuiApp/FileTime.Avalonia/FileTime.Avalonia.csproj +++ b/src/GuiApp/FileTime.Avalonia/FileTime.Avalonia.csproj @@ -4,7 +4,7 @@ net6.0 enable Assets\filetime.ico - 0.0.1 + 0.0.2 true diff --git a/src/GuiApp/FileTime.Avalonia/Services/CommandHandlerService.cs b/src/GuiApp/FileTime.Avalonia/Services/CommandHandlerService.cs index 12a3aac..437ff8e 100644 --- a/src/GuiApp/FileTime.Avalonia/Services/CommandHandlerService.cs +++ b/src/GuiApp/FileTime.Avalonia/Services/CommandHandlerService.cs @@ -810,7 +810,7 @@ namespace FileTime.Avalonia.Services } catch (System.ComponentModel.Win32Exception e) { - _logger.LogError(e, "Error while running editor program, possible the executable path does not exists. {0}", execPath); + _logger.LogError(e, "Error while running editor program, possible the executable path does not exists. {ExecutablePath}", execPath); } catch (Exception e) { diff --git a/src/GuiApp/FileTime.Avalonia/Services/KeyInputHandlerService.cs b/src/GuiApp/FileTime.Avalonia/Services/KeyInputHandlerService.cs index 88dddc8..9f85dcd 100644 --- a/src/GuiApp/FileTime.Avalonia/Services/KeyInputHandlerService.cs +++ b/src/GuiApp/FileTime.Avalonia/Services/KeyInputHandlerService.cs @@ -3,11 +3,13 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Avalonia.Input; +using FileTime.App.Core.Command; using FileTime.Avalonia.Application; using FileTime.Avalonia.Configuration; using FileTime.Avalonia.ViewModels; using FileTime.Core.Extensions; using FileTime.Core.Models; +using Microsoft.Extensions.Logging; namespace FileTime.Avalonia.Services { @@ -18,17 +20,20 @@ namespace FileTime.Avalonia.Services private readonly KeyboardConfigurationService _keyboardConfigurationService; private readonly CommandHandlerService _commandHandlerService; private readonly IDialogService _dialogService; + private readonly ILogger _logger; public KeyInputHandlerService( AppState appState, KeyboardConfigurationService keyboardConfigurationService, CommandHandlerService commandHandlerService, - IDialogService dialogService) + IDialogService dialogService, + ILogger logger) { _appState = appState; _keyboardConfigurationService = keyboardConfigurationService; _commandHandlerService = commandHandlerService; _dialogService = dialogService; + _logger = logger; _keysToSkip.Add(new KeyConfig[] { new KeyConfig(Key.Up) }); _keysToSkip.Add(new KeyConfig[] { new KeyConfig(Key.Down) }); @@ -82,7 +87,7 @@ namespace FileTime.Avalonia.Services setHandled(true); _appState.PreviousKeys.Clear(); _appState.PossibleCommands = new(); - await _commandHandlerService.HandleCommandAsync(selectedCommandBinding.Command); + await CallCommandAsync(selectedCommandBinding.Command); } else if (_keysToSkip.Any(k => AreKeysEqual(k, _appState.PreviousKeys))) { @@ -156,7 +161,7 @@ namespace FileTime.Avalonia.Services if (selectedCommandBinding != null) { setHandled(true); - await _commandHandlerService.HandleCommandAsync(selectedCommandBinding.Command); + await CallCommandAsync(selectedCommandBinding.Command); } } @@ -194,6 +199,18 @@ namespace FileTime.Avalonia.Services } } + private async Task CallCommandAsync(Commands command) + { + try + { + await _commandHandlerService.HandleCommandAsync(command); + } + catch (Exception e) + { + _logger.LogError(e, "Unknown error while running commnad. {Command}", command); + } + } + private static bool AreKeysEqual(IReadOnlyList collection1, IReadOnlyList collection2) { if (collection1.Count != collection2.Count) return false; diff --git a/src/GuiApp/FileTime.Avalonia/Services/StatePersistenceService.cs b/src/GuiApp/FileTime.Avalonia/Services/StatePersistenceService.cs index 46b20bf..81eb316 100644 --- a/src/GuiApp/FileTime.Avalonia/Services/StatePersistenceService.cs +++ b/src/GuiApp/FileTime.Avalonia/Services/StatePersistenceService.cs @@ -145,7 +145,7 @@ namespace FileTime.Avalonia.Services } catch (Exception e) { - _logger.LogError(e, "Unkown exception while restoring tab. {0}", JsonSerializer.Serialize(tab, _jsonOptions)); + _logger.LogError(e, "Unkown exception while restoring tab. {TabState}", JsonSerializer.Serialize(tab, _jsonOptions)); } } diff --git a/src/Providers/FileTime.Providers.Smb/Persistence/PersistenceService.cs b/src/Providers/FileTime.Providers.Smb/Persistence/PersistenceService.cs index 9745d5e..aa039aa 100644 --- a/src/Providers/FileTime.Providers.Smb/Persistence/PersistenceService.cs +++ b/src/Providers/FileTime.Providers.Smb/Persistence/PersistenceService.cs @@ -91,7 +91,7 @@ namespace FileTime.Providers.Smb.Persistence } catch(Exception e) { - _logger.LogError(e, "Unkown error while decrypting password for {0}", server.Name); + _logger.LogError(e, "Unkown error while decrypting password for {ServerName}", server.Name); } } }