From 807e9b54968c13d60bbd2ea1a969f9c83d081312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Fri, 2 Sep 2022 17:23:55 +0200 Subject: [PATCH] Don't crash Lua when the translation attempt fails. --- OpenRA.Game/Translation.cs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/OpenRA.Game/Translation.cs b/OpenRA.Game/Translation.cs index 0911a8c5d1..91b2f7b916 100644 --- a/OpenRA.Game/Translation.cs +++ b/OpenRA.Game/Translation.cs @@ -88,19 +88,19 @@ namespace OpenRA public bool TryGetString(string key, out string value, IDictionary arguments = null) { - if (!HasMessage(key)) - { - value = null; - return false; - } - - var fluentArguments = new Dictionary(); - if (arguments != null) - foreach (var (k, v) in arguments) - fluentArguments.Add(k, v.ToFluentType()); - try { + if (!HasMessage(key)) + { + value = null; + return false; + } + + var fluentArguments = new Dictionary(); + if (arguments != null) + foreach (var (k, v) in arguments) + fluentArguments.Add(k, v.ToFluentType()); + var result = bundle.TryGetAttrMsg(key, fluentArguments, out var errors, out value); foreach (var error in errors) Log.Write("debug", $"Translation of {key}: {error}"); @@ -109,7 +109,8 @@ namespace OpenRA } catch (Exception e) { - Log.Write("debug", $"Translation of {key}: {e}"); + Log.Write("debug", $"Translation of {key} failed:"); + Log.Write("debug", e); value = null; return false; }