From 11c05899a7457b706d3d7597f30074fb01d12f08 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Mon, 14 Aug 2023 09:39:15 -0500 Subject: [PATCH] Correctly print cmdline errors with braces --- Cmdline/Action/AuthToken.cs | 2 +- Cmdline/Action/GameInstance.cs | 6 +++--- Cmdline/Action/Install.cs | 19 ++++++++++--------- Cmdline/Main.cs | 2 +- Cmdline/Properties/Resources.Designer.cs | 3 +++ Cmdline/Properties/Resources.resx | 1 + 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Cmdline/Action/AuthToken.cs b/Cmdline/Action/AuthToken.cs index 71222c5497..a8852f7401 100644 --- a/Cmdline/Action/AuthToken.cs +++ b/Cmdline/Action/AuthToken.cs @@ -110,7 +110,7 @@ private int addAuthToken(AddAuthTokenOptions opts) } else { - user.RaiseError("Invalid host name: {0}", opts.host); + user.RaiseError(Properties.Resources.AuthTokenInvalidHostName, opts.host); } return Exit.OK; } diff --git a/Cmdline/Action/GameInstance.cs b/Cmdline/Action/GameInstance.cs index a61f5baaf7..e953831cd4 100644 --- a/Cmdline/Action/GameInstance.cs +++ b/Cmdline/Action/GameInstance.cs @@ -637,13 +637,13 @@ int badArgument() catch (BadInstallLocationKraken kraken) { // The folder exists and is not empty. - User.RaiseError(kraken.Message); + User.RaiseError("{0}", kraken.Message); return badArgument(); } catch (WrongGameVersionKraken kraken) { // Thrown because the specified game instance is too old for one of the selected DLCs. - User.RaiseError(kraken.Message); + User.RaiseError("{0}", kraken.Message); return badArgument(); } catch (NotKSPDirKraken kraken) @@ -651,7 +651,7 @@ int badArgument() // Something went wrong adding the new instance to the registry, // most likely because the newly created directory is somehow not valid. log.Error(kraken); - User.RaiseError(kraken.Message); + User.RaiseError("{0}", kraken.Message); return error(); } catch (InvalidKSPInstanceKraken) diff --git a/Cmdline/Action/Install.cs b/Cmdline/Action/Install.cs index 8f662580da..f30b825ec3 100644 --- a/Cmdline/Action/Install.cs +++ b/Cmdline/Action/Install.cs @@ -88,9 +88,10 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options) } catch (Kraken kraken) { - user.RaiseError(kraken.InnerException == null - ? kraken.Message - : $"{kraken.Message}: {kraken.InnerException.Message}"); + user.RaiseError("{0}", + kraken.InnerException == null + ? kraken.Message + : $"{kraken.Message}: {kraken.InnerException.Message}"); } } @@ -142,7 +143,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options) } catch (DependencyNotSatisfiedKraken ex) { - user.RaiseError(ex.Message); + user.RaiseError("{0}", ex.Message); user.RaiseMessage(Properties.Resources.InstallTryAgain); return Exit.ERROR; } @@ -214,7 +215,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options) catch (InconsistentKraken ex) { // The prettiest Kraken formats itself for us. - user.RaiseError(ex.InconsistenciesPretty); + user.RaiseError("{0}", ex.InconsistenciesPretty); user.RaiseMessage(Properties.Resources.InstallCancelled); return Exit.ERROR; } @@ -226,12 +227,12 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options) catch (MissingCertificateKraken kraken) { // Another very pretty kraken. - user.RaiseError(kraken.ToString()); + user.RaiseError("{0}", kraken.ToString()); return Exit.ERROR; } catch (DownloadThrottledKraken kraken) { - user.RaiseError(kraken.ToString()); + user.RaiseError("{0}", kraken.ToString()); user.RaiseMessage(Properties.Resources.InstallTryAuthToken, kraken.infoUrl); return Exit.ERROR; } @@ -242,12 +243,12 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options) } catch (ModuleDownloadErrorsKraken kraken) { - user.RaiseError(kraken.ToString()); + user.RaiseError("{0}", kraken.ToString()); return Exit.ERROR; } catch (DirectoryNotFoundKraken kraken) { - user.RaiseError(kraken.Message); + user.RaiseError("{0}", kraken.Message); return Exit.ERROR; } catch (ModuleIsDLCKraken kraken) diff --git a/Cmdline/Main.cs b/Cmdline/Main.cs index c9b4face73..25237e381a 100644 --- a/Cmdline/Main.cs +++ b/Cmdline/Main.cs @@ -331,7 +331,7 @@ private static int Scan(CKAN.GameInstance inst, IUser user, string next_command if (next_command == null) { - user.RaiseError(kraken.InconsistenciesPretty); + user.RaiseError("{0}", kraken.InconsistenciesPretty); user.RaiseError(Properties.Resources.ScanNotSaved); } else diff --git a/Cmdline/Properties/Resources.Designer.cs b/Cmdline/Properties/Resources.Designer.cs index 5838864125..cc3d941351 100644 --- a/Cmdline/Properties/Resources.Designer.cs +++ b/Cmdline/Properties/Resources.Designer.cs @@ -164,6 +164,9 @@ internal static string AuthTokenTokenHeader { internal static string AuthTokenHelpSummary { get { return (string)(ResourceManager.GetObject("AuthTokenHelpSummary", resourceCulture)); } } + internal static string AuthTokenInvalidHostName { + get { return (string)(ResourceManager.GetObject("AuthTokenHelpSummary", resourceCulture)); } + } internal static string AvailableHeader { get { return (string)(ResourceManager.GetObject("AvailableHeader", resourceCulture)); } diff --git a/Cmdline/Properties/Resources.resx b/Cmdline/Properties/Resources.resx index e9c7101153..1bcf812c03 100644 --- a/Cmdline/Properties/Resources.resx +++ b/Cmdline/Properties/Resources.resx @@ -154,6 +154,7 @@ Update recommended! Host Token Manage authentication tokens + Invalid host name: {0} Modules compatible with {0} {1} Manage the download cache path of CKAN Download cache set to {0}