diff options
| author | Jacob Palecki <[email protected]> | 2020-09-27 21:42:48 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-09-27 21:42:48 -0700 |
| commit | 7ccdb78b8c059de31e5b568b43f4547142d9aeb4 (patch) | |
| tree | 992816135721cf33e41a373b161cfaee5d104d84 | |
| parent | Fix tab behavior (diff) | |
| download | rawaccel-7ccdb78b8c059de31e5b568b43f4547142d9aeb4.tar.xz rawaccel-7ccdb78b8c059de31e5b568b43f4547142d9aeb4.zip | |
Handle errors from bad arg on write
| -rw-r--r-- | grapher/Models/AccelGUI.cs | 3 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 29 |
2 files changed, 30 insertions, 2 deletions
diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index c9c4ed0..15a0c0e 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -3,7 +3,6 @@ using grapher.Models.Mouse; using grapher.Models.Options; using grapher.Models.Serialized; using System; -using System.Drawing; using System.Windows.Forms; namespace grapher @@ -97,7 +96,7 @@ namespace grapher } else { - WriteButton.Text = "bad args"; + throw new Exception($"Bad arguments: \n {SettingsManager.ErrorStringFrom(errors)}"); } } diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 93cf42b..416823e 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -2,6 +2,7 @@ using System; using System.Windows.Forms; using System.Threading; +using System.Text; namespace grapher.Models.Serialized { @@ -47,6 +48,34 @@ namespace grapher.Models.Serialized #region Methods + public static string ErrorStringFrom(SettingsErrors errors) + { + StringBuilder builder = new StringBuilder(); + bool yPresent = errors.y?.Count > 0; + + if (yPresent) + { + builder.AppendLine("\nx:"); + } + + foreach (var error in errors.x) + { + builder.AppendLine(error); + } + + if (yPresent) + { + builder.AppendLine("\ny:"); + + foreach (var error in errors.y) + { + builder.AppendLine(error); + } + } + + return builder.ToString(); + } + public SettingsErrors TryUpdateActiveSettings(DriverSettings settings) { var errors = TryUpdateAccel(settings); |