{"record":{"id":"b8899580e7984fd5","repo":"babalae/better-genshin-impact","slug":"ipc","errorCode":null,"errorMessage":"实例 IPC 请求失败。","messagePattern":"实例 IPC 请求失败。","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Service/Instance/InstanceService.cs","lineNumber":607,"sourceCode":"    {\n        var application = Application.Current;\n        if (application is null)\n        {\n            Environment.Exit(0);\n            return;\n        }\n\n        _ = application.Dispatcher.BeginInvoke(new Action(application.Shutdown));\n    }\n\n    private static void EnsureSuccessfulResponse(InstanceIpcEnvelope response)\n    {\n        if (response.Success == true)\n        {\n            return;\n        }\n\n        throw new InvalidOperationException(\n            response.ErrorMessage ?? response.ErrorCode ?? \"实例 IPC 请求失败。\");\n    }\n\n    private static async Task AwaitBackgroundTaskAsync(Task? task)\n    {\n        if (task is null)\n        {\n            return;\n        }\n        try\n        {\n            await task.ConfigureAwait(false);\n        }\n        catch (Exception exception) when (exception is IOException\n                                          or OperationCanceledException\n                                          or ObjectDisposedException)\n        {\n            // HostedService 停止期间的正常清理。","sourceCodeStart":589,"sourceCodeEnd":625,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/Instance/InstanceService.cs#L589-L625","documentation":"Thrown by EnsureSuccessfulResponse as the fallback message when response.Success is not true (i.e., false or null) and both response.ErrorMessage and response.ErrorCode are null. The method checks Success == true for success; anything else throws InvalidOperationException. If the failure envelope was constructed without an error message or code (e.g., via new InstanceIpcEnvelope { Success = false }), this generic text is used.","triggerScenarios":"A remote IPC handler returned an InstanceIpcEnvelope with Success = false (or null) but did not populate ErrorCode or ErrorMessage. In normal operation, failures are created via InstanceIpcEnvelope.Failure(request, errorCode, errorMessage) which always sets both. This generic fallback fires only when the response was constructed differently or deserialized from a peer that omitted error details.","commonSituations":"A peer running a different version whose failure response schema omits error fields; a deserialization issue where ErrorCode/ErrorMessage were present in JSON but didn't map due to casing; a bug in a custom handler that returns a bare failure envelope; the remote's HandleAsync catch block returned Failure but the error message extraction (exception.GetBaseException().Message) returned null.","solutions":["Inspect the actual InstanceIpcEnvelope response object before the throw — log response.Success, response.ErrorCode, response.ErrorMessage, and response.Data to see what the peer actually sent.","Ensure all remote handlers use InstanceIpcEnvelope.Failure(request, errorCode, errorMessage) so error details are always populated.","Verify the JSON serialization settings (CamelCasePropertyNamesContractResolver, NullValueHandling.Ignore) are identical on both peers so ErrorCode/ErrorMessage are not dropped.","If this occurs with a specific operation, trace the handler on the remote side to confirm it returns a descriptive failure."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    EnsureSuccessfulResponse(response);\n}\ncatch (InvalidOperationException ex)\n{\n    // Log the full response for diagnosis\n    _logger.LogError(\"IPC 请求失败：Success={Success}, Code={Code}, Msg={Msg}\",\n        response.Success, response.ErrorCode, response.ErrorMessage);\n    throw;\n}","preventionTips":["Always use InstanceIpcEnvelope.Failure(request, errorCode, errorMessage) so error details are populated.","Verify serialization settings match between peers so ErrorCode/ErrorMessage survive the wire.","Log the full response envelope on failure for diagnostics."],"tags":["ipc","error-handling","response-validation","deserialization"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}