Skip to content

Commit

Permalink
Merge pull request #763 from NickvisionApps/more-logs
Browse files Browse the repository at this point in the history
Print to stderr when there is an exception
  • Loading branch information
nlogozzo authored Dec 26, 2023
2 parents 0b68871 + 4d3c096 commit f0f48eb
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 32 deletions.
4 changes: 2 additions & 2 deletions NickvisionMoney.GNOME/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public Program(string[] args)
@"* Fixed an issue where the generated ids of new transactions were incorrect.
* Fixed an issue that caused sort to behave inconsistently.
* Fixed calendar not showing marks for transactions after pressing the ""Today"" button.
* Added more logging to help debug issues.
* Updated and added translations (Thanks to everyone on Weblate)!";
_application.OnActivate += OnActivate;
if (File.Exists(Path.GetFullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) + "/org.nickvision.money.gresource"))
Expand Down Expand Up @@ -86,8 +87,7 @@ public int Run(string[] args)
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine($"\n\n{ex.StackTrace}");
Console.Error.WriteLine(ex);
return -1;
}
}
Expand Down
15 changes: 12 additions & 3 deletions NickvisionMoney.GNOME/Views/AccountView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,10 @@ private async void ImportFromFile(Gio.SimpleAction sender, EventArgs e)
_viewStack.SetVisibleChildName(_viewStack.GetVisibleChildName() == "spinner" ? oldPage : _viewStack.GetVisibleChildName());
_paneScroll.SetSensitive(true);
}
catch { }
catch (Exception ex)
{
Console.Error.WriteLine(ex);
}
}

/// <summary>
Expand All @@ -803,7 +806,10 @@ private async Task ExportToCSVAsync(ExportMode exportMode)
}
_controller.ExportToCSV(path ?? "", exportMode);
}
catch { }
catch (Exception e)
{
Console.Error.WriteLine(e);
}
}

/// <summary>
Expand Down Expand Up @@ -853,7 +859,10 @@ private async Task ExportToPDFAsync(ExportMode exportMode)
};
dialog.Present();
}
catch { }
catch (Exception e)
{
Console.Error.WriteLine(e);
}
}

/// <summary>
Expand Down
10 changes: 8 additions & 2 deletions NickvisionMoney.GNOME/Views/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ private void NotificationSent(object? sender, NotificationSentEventArgs e)
{
await fileLauncher.LaunchAsync(this);
}
catch { }
catch (Exception exception)
{
Console.Error.WriteLine(exception);
}
};
}
_toastOverlay.AddToast(toast);
Expand Down Expand Up @@ -309,7 +312,10 @@ private async void OnOpenAccount(Gio.SimpleAction sender, EventArgs e)
var file = await openFileDialog.OpenAsync(this);
await _controller.AddAccountAsync(file.GetPath());
}
catch { }
catch (Exception exception)
{
Console.Error.WriteLine(exception);
}
}

/// <summary>
Expand Down
10 changes: 8 additions & 2 deletions NickvisionMoney.GNOME/Views/NewAccountDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ private async void SelectFolder(object? sender, EventArgs e)
_folderRow.SetText(Path.GetFileName(_controller.Folder));
ValidateName();
}
catch { }
catch (Exception exception)
{
Console.Error.WriteLine(exception);
}
}

/// <summary>
Expand Down Expand Up @@ -469,7 +472,10 @@ private async void SelectImportFile(object? sender, EventArgs e)
_controller.ImportFile = file.GetPath();
_importRow.SetText(_controller.ImportFile);
}
catch { }
catch (Exception exception)
{
Console.Error.WriteLine(exception);
}
}

/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion NickvisionMoney.GNOME/Views/PreferencesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ private async void SelectBackupFolder(Gtk.Button sender, EventArgs e)
_csvBackupRow.SetText(path);
}
}
catch { }
catch (Exception exception)
{
Console.Error.WriteLine(exception);
}
}

/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion NickvisionMoney.GNOME/Views/TransactionDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@ private async void OnUploadReceipt(Gtk.Button sender, EventArgs e)
}
Validate();
}
catch { }
catch (Exception ex)
{
Console.Error.WriteLine(ex);
}
}
}
5 changes: 4 additions & 1 deletion NickvisionMoney.GNOME/Views/TransferDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ private async void OnSelectAccount(Gtk.Button sender, EventArgs e)
_destinationCurrencyRow.SetText("");
Validate();
}
catch { }
catch (Exception exception)
{
Console.Error.WriteLine(exception);
}
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion NickvisionMoney.Shared/Controllers/AccountViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,9 @@ public async Task ImportFromFileAsync(string path)
{
res = await _account.ImportFromFileAsync(path, TransactionDefaultColor, GroupDefaultColor);
}
catch
catch (Exception e)
{
Console.Error.WriteLine(e);
NotificationSent?.Invoke(this, new NotificationSentEventArgs(_("Unable to import information from the file. Please ensure that the app has permissions to access the file and try again."), NotificationSeverity.Error));
return;
}
Expand Down
6 changes: 4 additions & 2 deletions NickvisionMoney.Shared/Controllers/MainWindowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ public async Task<bool> NewAccountAsync(NewAccountDialogController controller)
{
accountViewController.Login(null);
}
catch
catch (Exception e)
{
Console.Error.WriteLine(e);
NotificationSent?.Invoke(this, new NotificationSentEventArgs(_("Unable to open the account. Please ensure that the app has permissions to access the file and try again."), NotificationSeverity.Error));
return false;
}
Expand Down Expand Up @@ -340,8 +341,9 @@ public async Task<bool> AddAccountAsync(string path, bool showOpenedNotification
return false;
}
}
catch
catch (Exception e)
{
Console.Error.WriteLine(e);
NotificationSent?.Invoke(this, new NotificationSentEventArgs(_("Unable to open the account. Please ensure that the app has permissions to access the file and try again."), NotificationSeverity.Error));
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<p>- Fixed an issue where the generated ids of new transactions were incorrect.</p>
<p>- Fixed an issue that caused sort to behave inconsistently.</p>
<p>- Fixed calendar not showing marks for transactions after pressing the "Today" button.</p>
<p>- Added more logging to help debug issues. </p>
<p>- Updated translations (Thanks to everyone on Weblate)!</p>
</description>
</release>
Expand Down
19 changes: 13 additions & 6 deletions NickvisionMoney.Shared/Models/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@ public bool Login(string? password)
_database.Open();
_loggedIn = true;
}
catch
catch (Exception e)
{
Console.Error.WriteLine(e);
_database.Close();
_database.Dispose();
_database = null;
Expand Down Expand Up @@ -1207,6 +1208,7 @@ public async Task<ImportResult> ImportFromFileAsync(string path, string defaultT
{
if (!System.IO.Path.Exists(path))
{
Console.Error.WriteLine($"File not found: {path}");
return ImportResult.Empty;
}
var extension = System.IO.Path.GetExtension(path).ToLower();
Expand All @@ -1222,6 +1224,7 @@ public async Task<ImportResult> ImportFromFileAsync(string path, string defaultT
{
return await ImportFromQIFAsync(path, defaultTransactionRGBA, defaultGroupRGBA);
}
Console.Error.WriteLine($"Unsupported file extension: {extension}");
return ImportResult.Empty;
}

Expand All @@ -1239,8 +1242,9 @@ private async Task<ImportResult> ImportFromCSVAsync(string path, string defaultT
{
lines = File.ReadAllLines(path);
}
catch
catch (Exception e)
{
Console.Error.WriteLine(e);
return ImportResult.Empty;
}
var importResult = new ImportResult();
Expand Down Expand Up @@ -1427,8 +1431,9 @@ private async Task<ImportResult> ImportFromOFXAsync(string path, string defaultT
{
ofx = new OFXDocumentParser().Import(ofxString);
}
catch
catch (Exception e)
{
Console.Error.WriteLine(e);
return ImportResult.Empty;
}
//Transactions
Expand Down Expand Up @@ -1471,8 +1476,9 @@ private async Task<ImportResult> ImportFromQIFAsync(string path, string defaultT
qif = QifDocument.Load(File.OpenRead(path));
Thread.CurrentThread.CurrentCulture = oldCulture;
}
catch
catch (Exception e)
{
Console.Error.WriteLine(e);
return ImportResult.Empty;
}
var importResult = new ImportResult();
Expand Down Expand Up @@ -1558,8 +1564,9 @@ public bool ExportToCSV(string path, ExportMode exportMode, List<uint> filteredI
File.WriteAllText(path, result);
return true;
}
catch
catch (Exception e)
{
Console.Error.WriteLine(e);
return false;
}
}
Expand Down Expand Up @@ -1851,7 +1858,7 @@ public bool ExportToPDF(string path, ExportMode exportMode, List<uint> filteredI
}
catch (Exception e)
{
Console.WriteLine(e);
Console.Error.WriteLine(e);
return false;
}
return true;
Expand Down
3 changes: 2 additions & 1 deletion NickvisionMoney.Shared/Models/AccountMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ internal static void UpdateMetadataDatabaseTable(SqliteConnection database)
{
database.Open();
}
catch
catch (Exception e)
{
Console.Error.WriteLine(e);
database.Close();
return null;
}
Expand Down
16 changes: 6 additions & 10 deletions NickvisionMoney.Shared/Models/CurrencyConversionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CurrencyConversion
/// <summary>
/// The currency code of the source amount
/// </summary>
public string SourceCurrnecy { get; init; }
public string SourceCurrency { get; init; }
/// <summary>
/// The source amount to convert
/// </summary>
Expand Down Expand Up @@ -44,7 +44,7 @@ public class CurrencyConversion
/// <param name="conversionRate">The rate of conversion from the source currency to the result currency</param>
public CurrencyConversion(string sourceCurrency, decimal sourceAmount, string resultCurrency, decimal conversionRate)
{
SourceCurrnecy = sourceCurrency;
SourceCurrency = sourceCurrency;
SourceAmount = sourceAmount;
ResultCurrency = resultCurrency;
ConversionRate = conversionRate;
Expand Down Expand Up @@ -114,8 +114,7 @@ static CurrencyConversionService()
catch (Exception e)
{
// Couldn't get the cached rates
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Console.Error.WriteLine(e);
needsUpdate = true;
json?.Dispose();
}
Expand All @@ -135,8 +134,7 @@ static CurrencyConversionService()
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Console.Error.WriteLine(e);
json?.Dispose();
return null;
}
Expand All @@ -155,16 +153,14 @@ static CurrencyConversionService()
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Console.Error.WriteLine(e);
}
}
return rates;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Console.Error.WriteLine(e);
return null;
}
finally
Expand Down

0 comments on commit f0f48eb

Please sign in to comment.