From 822452a20c36054837612cbf43e21795bead6ecc Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 18 Mar 2025 15:55:32 +0800 Subject: [PATCH] enhance: show inner exception message if possible when check update failed Signed-off-by: leo --- src/App.axaml.cs | 2 +- src/Models/{Version.cs => SelfUpdate.cs} | 24 ++++++++++++-- src/Views/SelfUpdate.axaml | 41 ++++++++++++------------ 3 files changed, 43 insertions(+), 24 deletions(-) rename src/Models/{Version.cs => SelfUpdate.cs} (65%) diff --git a/src/App.axaml.cs b/src/App.axaml.cs index f59d35db..af5e6177 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -532,7 +532,7 @@ namespace SourceGit catch (Exception e) { if (manually) - ShowSelfUpdateResult(e); + ShowSelfUpdateResult(new Models.SelfUpdateFailed(e)); } }); } diff --git a/src/Models/Version.cs b/src/Models/SelfUpdate.cs similarity index 65% rename from src/Models/Version.cs rename to src/Models/SelfUpdate.cs index 35c21778..e02f80d8 100644 --- a/src/Models/Version.cs +++ b/src/Models/SelfUpdate.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; using System.Text.Json.Serialization; namespace SourceGit.Models @@ -32,5 +33,24 @@ namespace SourceGit.Models } } - public class AlreadyUpToDate { } + public class AlreadyUpToDate + { + } + + public class SelfUpdateFailed + { + public string Reason + { + get; + private set; + } + + public SelfUpdateFailed(Exception e) + { + if (e.InnerException is { } inner) + Reason = inner.Message; + else + Reason = e.Message; + } + } } diff --git a/src/Views/SelfUpdate.axaml b/src/Views/SelfUpdate.axaml index 0a6fef34..2d5990e7 100644 --- a/src/Views/SelfUpdate.axaml +++ b/src/Views/SelfUpdate.axaml @@ -5,7 +5,6 @@ xmlns:m="using:SourceGit.Models" xmlns:vm="using:SourceGit.ViewModels" xmlns:v="using:SourceGit.Views" - xmlns:sys="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="SourceGit.Views.SelfUpdate" x:DataType="vm:SelfUpdate" @@ -87,26 +86,6 @@ - - - - - - - - - -