Skip to content

Commit a423b32

Browse files
authored
Merge pull request #915 from Tharylia/error-reason-tooltip
Added module FatalError tooltip with the reason on LoadAsync error
2 parents 71be1e8 + 688164c commit a423b32

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

Blish HUD/GameServices/Modules/Module.cs

+24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.ComponentModel.Composition;
3+
using System.Text;
34
using System.Threading.Tasks;
45
using Blish_HUD.Graphics.UI;
56
using Blish_HUD.Settings;
@@ -64,6 +65,8 @@ private set {
6465

6566
public bool Loaded => _runState == ModuleRunState.Loaded;
6667

68+
internal string ErrorReason { get; set; }
69+
6770
#region Manifest & Parameter Aliases
6871

6972
// Manifest
@@ -110,6 +113,7 @@ private void CheckForLoaded() {
110113

111114
if (!loadError.Observed && _loadTask.Exception != null) {
112115
Logger.GetLogger(GetType()).Error(_loadTask.Exception, "Module {module} had an unhandled exception while loading.", ModuleParameters.Manifest.GetDetailedName());
116+
this.ErrorReason = GetModuleErrorReason(_loadTask.Exception);
113117

114118
if (ApplicationSettings.Instance.DebugEnabled) {
115119
throw _loadTask.Exception;
@@ -137,6 +141,26 @@ private void CheckForLoaded() {
137141
}
138142
}
139143

144+
/// <summary>
145+
/// Builds a error reason for the module from the specified exception.
146+
/// </summary>
147+
/// <param name="ex">The exception to read to error reason from.</param>
148+
/// <returns>A string containing the error reasons.</returns>
149+
private static string GetModuleErrorReason(Exception ex) {
150+
if (ex is AggregateException ae && ae.InnerExceptions.Count > 0) {
151+
StringBuilder sb = new StringBuilder();
152+
foreach (Exception innerException in ae.InnerExceptions) {
153+
if (innerException != null) {
154+
sb.AppendLine(innerException.Message);
155+
}
156+
}
157+
158+
return sb.ToString().Trim();
159+
}
160+
161+
return ex.Message;
162+
}
163+
140164
public void DoUpdate(GameTime gameTime) {
141165
switch (_runState) {
142166
case ModuleRunState.Loaded:

Blish HUD/GameServices/Modules/UI/Presenters/ManageModulePresenter.cs

+14-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected override void UpdateView() {
2626

2727
this.Model.ModuleDisabled += ModelOnModuleDisabled;
2828

29-
this.View.EnableModuleClicked += ViewOnEnableModuleClicked;
29+
this.View.EnableModuleClicked += ViewOnEnableModuleClicked;
3030
this.View.DisableModuleClicked += ViewOnDisableModuleClicked;
3131

3232
SubscribeToModuleRunState();
@@ -73,14 +73,14 @@ private void InvalidateViewState(bool staticDetails = false, bool stateDetails =
7373
private void DisplayStaticDetails() {
7474
// Load static details based on the manifest
7575

76-
this.View.ModuleName = this.Model.Manifest.Name;
77-
this.View.ModuleNamespace = this.Model.Manifest.Namespace;
78-
this.View.ModuleDescription = this.Model.Manifest.Description;
79-
this.View.ModuleVersion = this.Model.Manifest.Version;
76+
this.View.ModuleName = this.Model.Manifest.Name;
77+
this.View.ModuleNamespace = this.Model.Manifest.Namespace;
78+
this.View.ModuleDescription = this.Model.Manifest.Description;
79+
this.View.ModuleVersion = this.Model.Manifest.Version;
8080
this.View.ModuleAssemblyStateDirtied = this.Model.IsModuleAssemblyStateDirty;
8181

8282
this.View.AuthorImage = GetModuleAuthorImage();
83-
this.View.AuthorName = GetModuleAuthor();
83+
this.View.AuthorName = GetModuleAuthor();
8484
}
8585

8686
private void DisplaySettingMenu() {
@@ -104,7 +104,7 @@ private ContextMenuStripItem BuildDeleteModuleMenuItem() {
104104
}
105105

106106
private ContextMenuStripItem BuildClearSettingsMenuItem() {
107-
var clearSettings = new ContextMenuStripItem() {Text = Strings.GameServices.ModulesService.ModuleOption_ClearSettings };
107+
var clearSettings = new ContextMenuStripItem() { Text = Strings.GameServices.ModulesService.ModuleOption_ClearSettings };
108108

109109
clearSettings.BasicTooltipText = (clearSettings.Enabled = !this.Model.Enabled) == true
110110
? Strings.GameServices.ModulesService.ModuleOption_ClearSettings_DescriptionEnabled
@@ -119,11 +119,11 @@ private IEnumerable<ContextMenuStripItem> BuildOpenDirsMenuItem() {
119119
var dirs = this.Model.Manifest.Directories ?? new List<string>(0);
120120

121121
foreach (string dir in dirs) {
122-
var dirItem = new ContextMenuStripItem() { Text = string.Format(Strings.GameServices.ModulesService.ModuleOption_OpenDir, dir.Titleize()) };
122+
var dirItem = new ContextMenuStripItem() { Text = string.Format(Strings.GameServices.ModulesService.ModuleOption_OpenDir, dir.Titleize()) };
123123
string dirPath = DirectoryUtil.RegisterDirectory(dir);
124124

125125
dirItem.BasicTooltipText = dirPath;
126-
dirItem.Enabled = Directory.Exists(dirPath);
126+
dirItem.Enabled = Directory.Exists(dirPath);
127127

128128
dirItem.Click += delegate {
129129
Process.Start("explorer.exe", $"/open, \"{dirPath}\\\"");
@@ -135,7 +135,10 @@ private IEnumerable<ContextMenuStripItem> BuildOpenDirsMenuItem() {
135135

136136
private void DisplayStateDetails() {
137137
if (!GameService.Module.ModuleIsExplicitlyIncompatible(this.Model)) {
138-
this.View.ModuleState = Model.ModuleInstance?.RunState ?? ModuleRunState.Unloaded;
138+
var runState = Model.ModuleInstance?.RunState ?? ModuleRunState.Unloaded;
139+
this.View.ModuleErrorReason = runState == ModuleRunState.FatalError ? this.Model.ModuleInstance?.ErrorReason : null;
140+
141+
this.View.ModuleState = runState;
139142

140143
GameService.Settings.Save();
141144
} else {
@@ -160,7 +163,7 @@ private void DisplaySettingsView(bool enable) {
160163
}
161164

162165
private void DisplayStatedOptions() {
163-
this.View.CanEnable = GetModuleCanEnable();
166+
this.View.CanEnable = GetModuleCanEnable();
164167
this.View.CanDisable = GetModuleCanDisable();
165168
}
166169

Blish HUD/GameServices/Modules/UI/Views/ManageModuleView.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public Version ModuleVersion {
7575
}
7676
}
7777

78+
public string ModuleErrorReason { get; set; }
79+
7880
private ModuleRunState _moduleRunState = ModuleRunState.Unloaded;
7981
public ModuleRunState ModuleState {
8082
get => _moduleRunState;
@@ -83,7 +85,7 @@ public ModuleRunState ModuleState {
8385

8486
var (status, color) = _moduleStatusLookup[_moduleRunState];
8587

86-
UpdateModuleRunState(status, color);
88+
UpdateModuleRunState(status, color, _moduleRunState == ModuleRunState.FatalError ? this.ModuleErrorReason : null);
8789

8890
UpdateHeaderLayout();
8991
}
@@ -351,9 +353,10 @@ private void UpdateHeaderLayout() {
351353
_moduleStateLabel.Location = new Point(_moduleVersionLabel.Right + 8, _moduleNameLabel.Top);
352354
}
353355

354-
private void UpdateModuleRunState(string status, Color color) {
356+
private void UpdateModuleRunState(string status, Color color, string tooltip = null) {
355357
_moduleStateLabel.Text = status;
356358
_moduleStateLabel.TextColor = color;
359+
_moduleStateLabel.BasicTooltipText = tooltip;
357360
}
358361

359362
}

0 commit comments

Comments
 (0)