{"record":{"id":"ec5ec18077f8bf27","repo":"EllanJiang/GameFramework","slug":"can-not-compress-with-exception-0","errorCode":null,"errorMessage":"Can not compress with exception '{0}'.","messagePattern":"Can not compress with exception '(.+?)'\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Utility/Utility.Compression.cs","lineNumber":125,"sourceCode":"                }\n\n                if (compressedStream == null)\n                {\n                    throw new GameFrameworkException(\"Compressed stream is invalid.\");\n                }\n\n                try\n                {\n                    return s_CompressionHelper.Compress(bytes, offset, length, compressedStream);\n                }\n                catch (Exception exception)\n                {\n                    if (exception is GameFrameworkException)\n                    {\n                        throw;\n                    }\n\n                    throw new GameFrameworkException(Text.Format(\"Can not compress with exception '{0}'.\", exception), exception);\n                }\n            }\n\n            /// <summary>\n            /// 压缩数据。\n            /// </summary>\n            /// <param name=\"stream\">要压缩的数据的二进制流。</param>\n            /// <returns>压缩后的数据的二进制流。</returns>\n            public static byte[] Compress(Stream stream)\n            {\n                using (MemoryStream compressedStream = new MemoryStream())\n                {\n                    if (Compress(stream, compressedStream))\n                    {\n                        return compressedStream.ToArray();\n                    }\n                    else\n                    {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Utility/Utility.Compression.cs#L107-L143","documentation":"Utility.Compress wraps any exception thrown by the configured compression helper (e.g. ZipHelper failures) into a GameFrameworkException with this message, unless the exception is already a GameFrameworkException (which is rethrown as-is). It signals the underlying compression operation failed, not a null-argument problem.","triggerScenarios":"Calling any Utility.Compress overload where the helper's Compress(stream, compressedStream) throws a non-GameFrameworkException (corrupt stream, unsupported data, IO error inside the helper).","commonSituations":"Feeding a stream whose data the zip implementation cannot handle (e.g. already-compressed or malformed data), disk full / IO errors while writing the compressed stream, or a custom ICompressionHelper with buggy internal logic.","solutions":["Read the inner exception (the InnerException / formatted '{0}') to find the real failure cause thrown by the compression helper.","Verify SetCompressionHelper was configured with a valid helper (e.g. Utility.Zip) and the input stream contains valid uncompressed data.","Check stream positions and write permissions on the destination stream; ensure it is writable and has enough space.","Wrap compression in try-catch and log the inner exception for diagnosis."],"exampleFix":"// before\nUtility.Compress(stream, compressedStream); // opaque failure\n// after\ntry { Utility.Compress(stream, compressedStream); }\ncatch (GameFrameworkException e) { Log.Error(\"Compression failed: {0}\", e.InnerException); }","handlingStrategy":"try-catch","validationCode":"if (stream == null || compressedStream == null) throw new ArgumentException(\"streams required\");","typeGuard":null,"tryCatchPattern":"try { Utility.Compress(stream, compressedStream); }\ncatch (GameFrameworkException e) { Log.Error(\"Compress failed: {0}\", e.InnerException ?? e); }","preventionTips":["Always log InnerException, not just the wrapper message","Validate streams are readable/writable before compressing","Register a known-good compression helper at startup"],"tags":["compression","utility","exception-wrapper"],"backgroundTag":"compression-failed","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}