More robust error handling, especially before logging can be initialized
This commit is contained in:
parent
61385f0f0b
commit
4fd16f04e0
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<Version>6.0.3.1</Version>
|
<Version>6.0.4.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -61,7 +61,16 @@ namespace AppScaffolding
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var startingContents = File.ReadAllText(APPSETTINGS_JSON);
|
var startingContents = File.ReadAllText(APPSETTINGS_JSON);
|
||||||
var jObj = JObject.Parse(startingContents);
|
|
||||||
|
JObject jObj;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
jObj = JObject.Parse(startingContents);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
action(jObj);
|
action(jObj);
|
||||||
|
|
||||||
@ -130,7 +139,16 @@ namespace AppScaffolding
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var startingContents = File.ReadAllText(SettingsJsonPath);
|
var startingContents = File.ReadAllText(SettingsJsonPath);
|
||||||
var jObj = JObject.Parse(startingContents);
|
|
||||||
|
JObject jObj;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
jObj = JObject.Parse(startingContents);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
action(jObj);
|
action(jObj);
|
||||||
|
|
||||||
|
|||||||
@ -33,10 +33,37 @@ namespace LibationWinForms.Dialogs
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void githubLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
private void githubLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||||||
=> Go.To.Url("https://github.com/rmcrackan/Libation/issues");
|
{
|
||||||
|
var url = "https://github.com/rmcrackan/Libation/issues";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Go.To.Url(url);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Error opening url\r\n{url}", "Error opening url", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void logsLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
private void logsLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||||||
=> Go.To.Folder(FileManager.Configuration.Instance.LibationFiles);
|
{
|
||||||
|
string dir = "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
dir = FileManager.Configuration.Instance.LibationFiles;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Go.To.Folder(dir);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Error opening folder\r\n{dir}", "Error opening folder", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void okBtn_Click(object sender, EventArgs e)
|
private void okBtn_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using LibationWinForms.Dialogs;
|
using System;
|
||||||
using System;
|
using LibationWinForms.Dialogs;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace LibationWinForms
|
namespace LibationWinForms
|
||||||
{
|
{
|
||||||
@ -15,7 +14,11 @@ namespace LibationWinForms
|
|||||||
/// <returns>One of the System.Windows.Forms.DialogResult values.</returns>
|
/// <returns>One of the System.Windows.Forms.DialogResult values.</returns>
|
||||||
public static System.Windows.Forms.DialogResult Show(string text, string caption, Exception exception)
|
public static System.Windows.Forms.DialogResult Show(string text, string caption, Exception exception)
|
||||||
{
|
{
|
||||||
Serilog.Log.Logger.Error(exception, "Alert admin error: {@DebugText}", new { text, caption });
|
try
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Error(exception, "Alert admin error: {@DebugText}", new { text, caption });
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
using var form = new MessageBoxAlertAdminDialog(text, caption, exception);
|
using var form = new MessageBoxAlertAdminDialog(text, caption, exception);
|
||||||
return form.ShowDialog();
|
return form.ShowDialog();
|
||||||
|
|||||||
@ -24,36 +24,54 @@ namespace LibationWinForms
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
//// Uncomment to see Console. Must be called before anything writes to Console.
|
try
|
||||||
//// Only use while debugging. Acts erratically in the wild
|
{
|
||||||
//AllocConsole();
|
//// Uncomment to see Console. Must be called before anything writes to Console.
|
||||||
|
//// Only use while debugging. Acts erratically in the wild
|
||||||
|
//AllocConsole();
|
||||||
|
|
||||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
|
||||||
//***********************************************//
|
//***********************************************//
|
||||||
// //
|
// //
|
||||||
// do not use Configuration before this line //
|
// do not use Configuration before this line //
|
||||||
// //
|
// //
|
||||||
//***********************************************//
|
//***********************************************//
|
||||||
// Migrations which must occur before configuration is loaded for the first time. Usually ones which alter the Configuration
|
// Migrations which must occur before configuration is loaded for the first time. Usually ones which alter the Configuration
|
||||||
var config = AppScaffolding.LibationScaffolding.RunPreConfigMigrations();
|
var config = AppScaffolding.LibationScaffolding.RunPreConfigMigrations();
|
||||||
|
|
||||||
RunInstaller(config);
|
RunInstaller(config);
|
||||||
|
|
||||||
// most migrations go in here
|
// most migrations go in here
|
||||||
AppScaffolding.LibationScaffolding.RunPostConfigMigrations();
|
AppScaffolding.LibationScaffolding.RunPostConfigMigrations();
|
||||||
|
|
||||||
// migrations which require Forms or are long-running
|
// migrations which require Forms or are long-running
|
||||||
RunWindowsOnlyMigrations(config);
|
RunWindowsOnlyMigrations(config);
|
||||||
|
|
||||||
MessageBoxVerboseLoggingWarning.ShowIfTrue();
|
MessageBoxVerboseLoggingWarning.ShowIfTrue();
|
||||||
|
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
checkForUpdate();
|
checkForUpdate();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var title = "Fatal error, pre-logging";
|
||||||
|
var body = "An unrecoverable error occurred. Since this error happened before logging could be initialized, this error can not be written to the log file.";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
MessageBoxAlertAdmin.Show(body, title, ex);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
MessageBox.Show($"{body}\r\n\r\n{ex.Message}\r\n\r\n{ex.StackTrace}", title, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
AppScaffolding.LibationScaffolding.RunPostMigrationScaffolding();
|
AppScaffolding.LibationScaffolding.RunPostMigrationScaffolding();
|
||||||
|
|
||||||
Application.Run(new Form1());
|
Application.Run(new Form1());
|
||||||
@ -300,14 +318,14 @@ namespace LibationWinForms
|
|||||||
if (result != DialogResult.Yes)
|
if (result != DialogResult.Yes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
using var fileSelector = new SaveFileDialog { FileName = zipName, Filter = "Zip Files (*.zip)|*.zip|All files (*.*)|*.*" };
|
|
||||||
if (fileSelector.ShowDialog() != DialogResult.OK)
|
|
||||||
return;
|
|
||||||
var selectedPath = fileSelector.FileName;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LibationWinForms.BookLiberation.ProcessorAutomationController.DownloadFile(zipUrl, selectedPath, true);
|
using var fileSelector = new SaveFileDialog { FileName = zipName, Filter = "Zip Files (*.zip)|*.zip|All files (*.*)|*.*" };
|
||||||
|
if (fileSelector.ShowDialog() != DialogResult.OK)
|
||||||
|
return;
|
||||||
|
var selectedPath = fileSelector.FileName;
|
||||||
|
|
||||||
|
BookLiberation.ProcessorAutomationController.DownloadFile(zipUrl, selectedPath, true);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user