Better error messages

This commit is contained in:
2022-02-15 21:26:13 +01:00
parent 20d26340b0
commit 89d891918c
5 changed files with 24 additions and 7 deletions

View File

@@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ApplicationIcon>Assets\filetime.ico</ApplicationIcon>
<Version>0.0.1</Version>
<Version>0.0.2</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DebugSymbols>true</DebugSymbols>

View File

@@ -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)
{

View File

@@ -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<KeyInputHandlerService> _logger;
public KeyInputHandlerService(
AppState appState,
KeyboardConfigurationService keyboardConfigurationService,
CommandHandlerService commandHandlerService,
IDialogService dialogService)
IDialogService dialogService,
ILogger<KeyInputHandlerService> 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<KeyConfig> collection1, IReadOnlyList<KeyConfig> collection2)
{
if (collection1.Count != collection2.Count) return false;

View File

@@ -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));
}
}