{"record":{"id":"0683ad89f176b201","repo":"EllanJiang/GameFramework","slug":"format-is-invalid","errorCode":null,"errorMessage":"Format is invalid.","messagePattern":"Format is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Utility/Utility.Text.cs","lineNumber":39,"sourceCode":"            /// </summary>\n            /// <param name=\"textHelper\">要设置的字符辅助器。</param>\n            public static void SetTextHelper(ITextHelper textHelper)\n            {\n                s_TextHelper = textHelper;\n            }\n\n            /// <summary>\n            /// 获取格式化字符串。\n            /// </summary>\n            /// <typeparam name=\"T\">字符串参数的类型。</typeparam>\n            /// <param name=\"format\">字符串格式。</param>\n            /// <param name=\"arg\">字符串参数。</param>\n            /// <returns>格式化后的字符串。</returns>\n            public static string Format<T>(string format, T arg)\n            {\n                if (format == null)\n                {\n                    throw new GameFrameworkException(\"Format is invalid.\");\n                }\n\n                if (s_TextHelper == null)\n                {\n                    return string.Format(format, arg);\n                }\n\n                return s_TextHelper.Format(format, arg);\n            }\n\n            /// <summary>\n            /// 获取格式化字符串。\n            /// </summary>\n            /// <typeparam name=\"T1\">字符串参数 1 的类型。</typeparam>\n            /// <typeparam name=\"T2\">字符串参数 2 的类型。</typeparam>\n            /// <param name=\"format\">字符串格式。</param>\n            /// <param name=\"arg1\">字符串参数 1。</param>\n            /// <param name=\"arg2\">字符串参数 2。</param>","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Utility/Utility.Text.cs#L21-L57","documentation":"Utility.Text.Format<T>(string format, T arg) throws when the format string is null. The method routes to a configured TextHelper or falls back to string.Format, both of which require a non-null format string. The library fails fast with GameFrameworkException rather than returning null.","triggerScenarios":"Calling Utility.Text.Format<string>(null, arg) — typically because the format string came from a localization table, config value, or resource key lookup that returned null.","commonSituations":"Missing localization key so the lookup returns null; a config field left blank; refactoring where a format constant was deleted but a call site remained.","solutions":["Ensure the format string is non-null; check the source (localization/config lookup) for missing keys.","Provide a default format string when the lookup fails.","Validate format strings at load time so missing keys are caught at startup."],"exampleFix":"// before\nstring fmt = localization.GetString(key); // may be null\nstring text = Utility.Text.Format(fmt, value);\n// after\nstring fmt = localization.GetString(key) ?? \"Value: {0}\";\nstring text = Utility.Text.Format(fmt, value);","handlingStrategy":"validation","validationCode":"if (format == null)\n    format = DefaultFormat;\nstring text = Utility.Text.Format(format, arg);","typeGuard":"bool HasFormat(string format) => format != null;","tryCatchPattern":"try\n{\n    string text = Utility.Text.Format(fmt, arg);\n}\ncatch (GameFrameworkException ex) when (ex.Message == \"Format is invalid.\")\n{\n    // missing localization key: fall back to a default string\n}","preventionTips":["Make localization lookups return a fallback string instead of null.","Validate localization tables at startup so missing keys fail fast there.","Keep format strings as named constants rather than ad-hoc lookups."],"tags":["string-format","null-check","gameframework"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}