{"record":{"id":"4c33f6c949a167ea","repo":"EllanJiang/GameFramework","slug":"string-0-is-too-long","errorCode":null,"errorMessage":"String '{0}' is too long.","messagePattern":"String '(.+?)' is too long\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/FileSystem/FileSystem.StringData.cs","lineNumber":56,"sourceCode":"                    return null;\n                }\n\n                Array.Copy(m_Bytes, 0, s_CachedBytes, 0, m_Length);\n                Utility.Encryption.GetSelfXorBytes(s_CachedBytes, 0, m_Length, encryptBytes);\n                return Utility.Converter.GetString(s_CachedBytes, 0, m_Length);\n            }\n\n            public StringData SetString(string value, byte[] encryptBytes)\n            {\n                if (string.IsNullOrEmpty(value))\n                {\n                    return Clear();\n                }\n\n                int length = Utility.Converter.GetBytes(value, s_CachedBytes);\n                if (length > byte.MaxValue)\n                {\n                    throw new GameFrameworkException(Utility.Text.Format(\"String '{0}' is too long.\", value));\n                }\n\n                Utility.Encryption.GetSelfXorBytes(s_CachedBytes, encryptBytes);\n                Array.Copy(s_CachedBytes, 0, m_Bytes, 0, length);\n                return new StringData((byte)length, m_Bytes);\n            }\n\n            public StringData Clear()\n            {\n                return new StringData(0, m_Bytes);\n            }\n        }\n    }\n}\n","sourceCodeStart":38,"sourceCodeEnd":71,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/FileSystem/FileSystem.StringData.cs#L38-L71","documentation":"FileSystem.StringData.SetString converts a string to bytes and stores its length in a single byte, so strings longer than 255 bytes cannot be stored. GameFramework detects this and throws instead of silently truncating.","triggerScenarios":"Calling SetString with a string whose UTF-8/encoded byte count (from Utility.Converter.GetBytes) exceeds 255 while the filesystem is in write mode. Note the limit is on encoded BYTES, not characters — multibyte characters hit it sooner.","commonSituations":"Storing file names or metadata with long non-ASCII text (e.g. CJK or emoji names) where 255 characters fit but 255 bytes do not; user-generated names without length validation in editor tooling.","solutions":["Validate that Utility.Converter.GetBytes(value) returns at most 255 bytes before calling SetString","Shorten or truncate the string by encoded byte count, not character count, accounting for multibyte characters","Store long strings in a separate file outside the filesystem metadata instead of in StringData","Use ASCII-safe names where possible to maximize the usable length"],"exampleFix":"// before\nstringData.SetString(longName); // may exceed 255 encoded bytes\n// after\nint byteLen = Utility.Converter.GetBytes(longName, s_CachedBytes);\nif (byteLen > byte.MaxValue) longName = TruncateToBytes(longName, byte.MaxValue);\nstringData.SetString(longName);","handlingStrategy":"validation","validationCode":"int len = Utility.Converter.GetBytes(value, s_CachedBytes);\nif (len > byte.MaxValue) throw new ArgumentException($\"String exceeds {byte.MaxValue} encoded bytes\", nameof(value));\nstringData.SetString(value);","typeGuard":"bool FitsStringData(string s) { var b = new List<byte>(); Utility.Converter.GetBytes(s, b); return b.Count <= byte.MaxValue; }","tryCatchPattern":"try { stringData.SetString(value); }\ncatch (GameFrameworkException ex) when (ex.Message.Contains(\"is too long\")) { value = TruncateToBytes(value, byte.MaxValue); stringData.SetString(value); }","preventionTips":["Limit strings by encoded byte count, not character count","Keep filesystem metadata strings short and ASCII-safe","Store long text in separate files, not in StringData entries"],"tags":["gameframework","filesystem","string-length"],"backgroundTag":"payload-too-large","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}