Skip to content

Commit

Permalink
Merge pull request #1086 from maiko3tattun/0328_ErrorDetailExpander
Browse files Browse the repository at this point in the history
Translate error messages and put them in the expander
  • Loading branch information
stakira authored Apr 20, 2024
2 parents 46889e4 + 02e8d8e commit a849c77
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 36 deletions.
2 changes: 1 addition & 1 deletion OpenUtau.Core/Classic/Frq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public bool Load(string wavPath) {
}
return true;
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("failed to load frq file", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.load", ": frq file", e));
return false;
}
}
Expand Down
14 changes: 14 additions & 0 deletions OpenUtau.Core/Commands/Notifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ public ErrorMessageNotification(string message, Exception e) {
public override string ToString() => $"Error message: {message} {e}";
}

public class ErrorMessageNotificationWithTranslation : ErrorMessageNotification {
public readonly string stringKey = string.Empty;
public ErrorMessageNotificationWithTranslation(string stringKey) : base(string.Empty) {
this.stringKey = stringKey;
}
public ErrorMessageNotificationWithTranslation(string stringKey, Exception e) : base(e) {
this.stringKey = stringKey;
}
public ErrorMessageNotificationWithTranslation(string stringKey, string additionalMessage, Exception e) : base(additionalMessage, e) {
this.stringKey = stringKey;
}
public override string ToString() => $"Error message: {stringKey}{message} {e}";
}

public class LoadingNotification : UNotification {
public readonly Type window;
public readonly bool startLoading;
Expand Down
10 changes: 5 additions & 5 deletions OpenUtau.Core/PlaybackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void Render(UProject project, int tick, int endTick, int trackNo) {
} catch (Exception e) {
Log.Error(e, "Failed to render.");
StopPlayback();
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to render.", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.render", e));
}
});
}
Expand Down Expand Up @@ -161,10 +161,10 @@ await Task.Run(() => {
WaveFileWriter.CreateWaveFile16(exportPath, new ExportAdapter(projectMix).ToMono(1, 0));
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(0, $"Exported to {exportPath}."));
} catch (IOException ioe) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification($"Failed to export {exportPath}.", ioe));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.export", $": {exportPath}", ioe));
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(0, $"Failed to export {exportPath}."));
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to render.", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.render", e));
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(0, $"Failed to render."));
}
});
Expand All @@ -189,10 +189,10 @@ await Task.Run(() => {
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(0, $"Exported to {file}."));
}
} catch (IOException ioe) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification($"Failed to export {file}.", ioe));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.export", $": {file}", ioe));
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(0, $"Failed to export {file}."));
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to render.", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.render", e));
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(0, $"Failed to render."));
}
});
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau.Core/Render/RenderEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Tuple<WaveMix, List<Fader>> RenderMixdown(TaskScheduler uiScheduler, ref
if (task.IsFaulted && !wait) {
Log.Error(task.Exception.Flatten(), "Failed to render.");
PlaybackManager.Inst.StopPlayback();
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to render.", task.Exception));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.render", task.Exception));
}
}, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, uiScheduler);
if (wait) {
Expand Down
8 changes: 8 additions & 0 deletions OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
<system:String x:Key="dialogs.voicecolorremapping.caption">Applies to all notes in this track:</system:String>

<system:String x:Key="errors.caption">Error</system:String>
<system:String x:Key="errors.details">Error Details</system:String>
<system:String x:Key="errors.failed.export">Failed to export</system:String>
<system:String x:Key="errors.failed.load">Failed to load</system:String>
<system:String x:Key="errors.failed.open">Failed to open</system:String>
<system:String x:Key="errors.failed.render">Failed to render.</system:String>
<system:String x:Key="errors.failed.runeditingmacro">Failed to run editing macro.</system:String>
<system:String x:Key="errors.failed.save">Failed to save</system:String>
<system:String x:Key="errors.failed.savesingerconfig">Failed to save singer config file.</system:String>

<system:String x:Key="exps.abbr">Abbreviation</system:String>
<system:String x:Key="exps.apply">Apply</system:String>
Expand Down
8 changes: 8 additions & 0 deletions OpenUtau/Strings/Strings.ja-JP.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
<system:String x:Key="dialogs.voicecolorremapping.caption">このトラック内のすべての音符に適用されます:</system:String>

<system:String x:Key="errors.caption">エラー</system:String>
<system:String x:Key="errors.details">エラーの詳細</system:String>
<system:String x:Key="errors.failed.export">エクスポートに失敗しました</system:String>
<system:String x:Key="errors.failed.load">読み込みに失敗しました</system:String>
<system:String x:Key="errors.failed.open">読み込みに失敗しました</system:String>
<system:String x:Key="errors.failed.render">レンダリングに失敗しました。</system:String>
<system:String x:Key="errors.failed.runeditingmacro">一括処理に失敗しました。</system:String>
<system:String x:Key="errors.failed.save">保存に失敗しました</system:String>
<system:String x:Key="errors.failed.savesingerconfig">シンガー設定の保存に失敗しました。</system:String>

<system:String x:Key="exps.abbr">パラメータの略称</system:String>
<system:String x:Key="exps.apply">適用</system:String>
Expand Down
4 changes: 2 additions & 2 deletions OpenUtau/ViewModels/EditSubbanksViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void LoadSubbanks() {
}
SelectedColor = Colors[0];
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to load subbanks", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.load", ": subbanks", e));
}
}

Expand Down Expand Up @@ -184,7 +184,7 @@ public void SaveSubbanks() {
bankConfig.Save(stream);
}
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to save subbanks", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.save", ": subbanks", e));
}
LoadSubbanks();
}
Expand Down
6 changes: 3 additions & 3 deletions OpenUtau/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public MainWindowViewModel() {
try {
OpenProject(new[] { file });
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("failed to open recent.", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.open", ": recent project", e));
}
});
OpenTemplateCommand = ReactiveCommand.Create<string>(file => {
Expand All @@ -72,7 +72,7 @@ public MainWindowViewModel() {
DocManager.Inst.Project.Saved = false;
DocManager.Inst.Project.FilePath = string.Empty;
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("failed to open template.", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.open", ": project template", e));
}
});
PartDeleteCommand = ReactiveCommand.Create<UPart>(part => {
Expand Down Expand Up @@ -111,7 +111,7 @@ public void NewProject() {
DocManager.Inst.Project.FilePath = string.Empty;
return;
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("failed to load default template.", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.load", ": default template", e));
}
}
DocManager.Inst.ExecuteCmd(new LoadProjectNotification(Core.Format.Ustx.Create()));
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau/ViewModels/PianoRollViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public PianoRollViewModel() {
try{
edit.Run(NotesViewModel.Project, NotesViewModel.Part, NotesViewModel.Selection.ToList(), DocManager.Inst);
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to run editing macro", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.runeditingmacro", e));
}
}
});
Expand Down
26 changes: 13 additions & 13 deletions OpenUtau/ViewModels/SingersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ private void SetEncoding(Encoding encoding) {
}
try {
ModifyConfig(Singer, config => config.TextFileEncoding = encoding.WebName);
Refresh();
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to set encoding", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.savesingerconfig", e));
}
Refresh();
}

public void SetImage(string filepath) {
Expand All @@ -169,10 +169,10 @@ public void SetImage(string filepath) {
}
try {
ModifyConfig(Singer, config => config.Image = filepath);
Refresh();
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to set image", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.savesingerconfig", e));
}
Refresh();
}

public void SetPortrait(string filepath) {
Expand All @@ -181,10 +181,10 @@ public void SetPortrait(string filepath) {
}
try {
ModifyConfig(Singer, config => config.Portrait = filepath);
Refresh();
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to set portrait", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.savesingerconfig", e));
}
Refresh();
}

private void SetSingerType(string singerType) {
Expand All @@ -193,10 +193,10 @@ private void SetSingerType(string singerType) {
}
try {
ModifyConfig(Singer, config => config.SingerType = singerType);
Refresh();
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to set singer type", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.savesingerconfig", e));
}
Refresh();
}

private void SetDefaultPhonemizer(Api.PhonemizerFactory factory) {
Expand All @@ -205,10 +205,10 @@ private void SetDefaultPhonemizer(Api.PhonemizerFactory factory) {
}
try {
ModifyConfig(Singer, config => config.DefaultPhonemizer = factory.type.FullName ?? string.Empty);
Refresh();
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to set portrait", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.savesingerconfig", e));
}
Refresh();
}

public void SetUseFilenameAsAlias() {
Expand All @@ -217,10 +217,10 @@ public void SetUseFilenameAsAlias() {
}
try {
ModifyConfig(Singer, config => config.UseFilenameAsAlias = !this.UseFilenameAsAlias);
Refresh();
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to set use filename", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.savesingerconfig", e));
}
Refresh();
}

private static void ModifyConfig(USinger singer, Action<VoicebankConfig> modify) {
Expand Down Expand Up @@ -338,7 +338,7 @@ public void LoadSubbanks() {
try {
Subbanks.AddRange(Singer.Subbanks);
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to load subbanks", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.load", ": subbanks", e));
}
}

Expand Down
4 changes: 2 additions & 2 deletions OpenUtau/Views/EditSubbanksDialog.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async void OnImportMap(object sender, RoutedEventArgs args) {
}
}
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to load prefix map", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.load", ": prefix map", e));
}
}
}
Expand All @@ -102,7 +102,7 @@ async void OnExportMap(object sender, RoutedEventArgs args) {
}
}
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Failed to save prefix map", e));
DocManager.Inst.ExecuteCmd(new ErrorMessageNotificationWithTranslation("errors.failed.save", ": prefix map", e));
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion OpenUtau/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,11 @@ public void OnNext(UCommand cmd, bool isUndo) {
MessageBox.MessageBoxButtons.Ok);
break;
default:
MessageBox.ShowError(this, notif.message, notif.e);
if (notif is ErrorMessageNotificationWithTranslation translatedNotif) {
MessageBox.ShowError(this, ThemeManager.GetString(translatedNotif.stringKey) + translatedNotif.message, translatedNotif.e);
} else {
MessageBox.ShowError(this, notif.message, notif.e);
}
break;
}
} else if (cmd is LoadingNotification loadingNotif && loadingNotif.window == typeof(MainWindow)) {
Expand Down
10 changes: 10 additions & 0 deletions OpenUtau/Views/MessageBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>

<!-- Show simple text -->
<TextBlock Margin="20" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Name="Text" TextWrapping="Wrap" MaxWidth="560"/>

<!-- Show text with URL button -->
<StackPanel Margin="20" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Name="TextPanel" MaxWidth="560">
<StackPanel.Styles>
<Style Selector="TextBlock">
Expand All @@ -39,8 +43,14 @@
</ControlTemplate>
</Setter>
</Style>
<Style Selector="Expander">
<Setter Property="Margin" Value="0, 20, 0, 0" />
<Setter Property="Width" Value="560" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
</StackPanel.Styles>
</StackPanel>

<StackPanel Grid.Row="1" HorizontalAlignment="Center" Orientation="Horizontal" Name="Buttons">
<StackPanel.Styles>
<Style Selector="Button">
Expand Down
25 changes: 20 additions & 5 deletions OpenUtau/Views/MessageBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,50 @@ public static Task<MessageBoxResult> ShowError(Window parent, Exception? e) {
}

public static Task<MessageBoxResult> ShowError(Window parent, string message, Exception? e) {
string text = message;

var builder = new StringBuilder();
if (!string.IsNullOrEmpty(message)) {
builder.AppendLine(message);
}
if (e != null) {
if (e is AggregateException ae) {
ae = ae.Flatten();
builder.AppendLine(ae.InnerExceptions.First().Message);
builder.AppendLine();
builder.Append(ae.ToString());
if (string.IsNullOrEmpty(text)) {
text = ae.InnerExceptions.First().Message;
}
} else {
builder.AppendLine(e.Message);
builder.AppendLine();
builder.Append(e.ToString());
if (string.IsNullOrEmpty(text)) {
text = e.Message;
}
}
}
builder.AppendLine();
builder.AppendLine();
builder.AppendLine(System.Reflection.Assembly.GetEntryAssembly()?.GetName().Version?.ToString() ?? "Unknown Version");
string title = ThemeManager.GetString("errors.caption");
return Show(parent, builder.ToString(), title, MessageBoxButtons.OkCopy);

return Show(parent, text, builder.ToString(), title, MessageBoxButtons.OkCopy);
}

public static Task<MessageBoxResult> Show(Window parent, string text, string title, MessageBoxButtons buttons) {
return Show(parent, text, null, title, buttons);
}
public static Task<MessageBoxResult> Show(Window parent, string text, string? stackTrace, string title, MessageBoxButtons buttons) {
var msgbox = new MessageBox() {
Title = title
};
msgbox.Text.IsVisible = false;
msgbox.SetTextWithLink(text, msgbox.TextPanel);
if (stackTrace != null) {
var stackTracePanel = new StackPanel();
var expander = new Expander() { Header = ThemeManager.GetString("errors.details"), Content = stackTracePanel };
msgbox.TextPanel.Children.Add(expander);
msgbox.SetTextWithLink(stackTrace, stackTracePanel);
}

var res = MessageBoxResult.Ok;

Expand Down Expand Up @@ -86,7 +101,7 @@ void AddButton(string caption, MessageBoxResult r, bool def = false) {
var btn = new Button { Content = ThemeManager.GetString("dialogs.messagebox.copy") };
btn.Click += (_, __) => {
try {
GetTopLevel(parent)?.Clipboard?.SetTextAsync(text);
GetTopLevel(parent)?.Clipboard?.SetTextAsync(text + "\n" + stackTrace);
} catch { }
};
msgbox.Buttons.Children.Add(btn);
Expand Down
Loading

0 comments on commit a849c77

Please sign in to comment.