{"record":{"id":"9aa2cc80bc182c63","repo":"EllanJiang/GameFramework","slug":"key-is-invalid","errorCode":null,"errorMessage":"Key is invalid.","messagePattern":"Key is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Localization/LocalizationManager.cs","lineNumber":993,"sourceCode":"                return Utility.Text.Format(value, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16);\n            }\n            catch (Exception exception)\n            {\n                string args = Utility.Text.Format(\"{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15}\", arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16);\n                return Utility.Text.Format(\"<Error>{0},{1},{2},{3}\", key, value, args, exception);\n            }\n        }\n\n        /// <summary>\n        /// 是否存在字典。\n        /// </summary>\n        /// <param name=\"key\">字典主键。</param>\n        /// <returns>是否存在字典。</returns>\n        public bool HasRawString(string key)\n        {\n            if (string.IsNullOrEmpty(key))\n            {\n                throw new GameFrameworkException(\"Key is invalid.\");\n            }\n\n            return m_Dictionary.ContainsKey(key);\n        }\n\n        /// <summary>\n        /// 根据字典主键获取字典值。\n        /// </summary>\n        /// <param name=\"key\">字典主键。</param>\n        /// <returns>字典值。</returns>\n        public string GetRawString(string key)\n        {\n            if (string.IsNullOrEmpty(key))\n            {\n                throw new GameFrameworkException(\"Key is invalid.\");\n            }\n\n            string value = null;","sourceCodeStart":975,"sourceCodeEnd":1011,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Localization/LocalizationManager.cs#L975-L1011","documentation":"HasRawString validates its dictionary key before checking the localization dictionary. An empty or null key can never exist in m_Dictionary, so rather than returning a misleading false the manager throws to signal a caller bug. Raw strings are the unformatted entries stored under a key in the localization system.","triggerScenarios":"Calling HasRawString(null) or HasRawString(\"\"), usually when the key string came from an unset variable, an empty UI field, or a parsed data row with a missing key column.","commonSituations":"Localization table rows whose key cell is blank; string variables not yet initialized at call time; concatenating key parts where one segment is empty producing an empty or clearly malformed key.","solutions":["Ensure the key is a non-empty string before calling, e.g. guard with if (!string.IsNullOrEmpty(key)).","Fix the data source so localization table rows always carry a key.","If a missing key is expected, treat it as 'not found' in your own wrapper instead of passing null/empty into the API."],"exampleFix":"// before\nbool exists = Localization.HasRawString(configKey); // configKey may be \"\"\n\n// after\nbool exists = !string.IsNullOrEmpty(configKey) && Localization.HasRawString(configKey);","handlingStrategy":"validation","validationCode":"bool exists = !string.IsNullOrEmpty(key) && Localization.HasRawString(key);","typeGuard":null,"tryCatchPattern":"try { exists = Localization.HasRawString(key); }\ncatch (GameFrameworkException) { exists = false; }","preventionTips":["Guard all raw-string lookups with string.IsNullOrEmpty checks.","Ensure localization data sources never emit blank key cells.","Wrap localization access in a helper layer that normalizes/validates keys once."],"tags":["localization","empty-string","validation"],"backgroundTag":"empty-required-field","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"}