{"record":{"id":"eb5997630159aaca","repo":"babalae/better-genshin-impact","slug":"error-eb5997","errorCode":null,"errorMessage":"当前动作已经设置完成条件，不能再次修改或添加","messagePattern":"当前动作已经设置完成条件，不能再次修改或添加","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"BetterGenshinImpact/Core/BgiVision/BvFlowAction.cs","lineNumber":257,"sourceCode":"            retryInterval = _retryInterval ?? _flow.DefaultRetryInterval;\n        }\n\n        var targetDescription = DescribeTargets(targets, condition);\n        return _flow.AddActionStep(new BvFlowActionSnapshot(\n            _description,\n            _action,\n            targets,\n            targetDescription,\n            timeout,\n            retryInterval,\n            condition));\n    }\n\n    private void EnsureNotCompleted()\n    {\n        if (_completed)\n        {\n            throw new InvalidOperationException(\"当前动作已经设置完成条件，不能再次修改或添加\");\n        }\n    }\n\n    private static void ValidateWaitOptions(int? timeout, int? retryInterval)\n    {\n        if (timeout is { } timeoutValue)\n        {\n            BvFlow.ValidatePositive(timeoutValue, nameof(timeout));\n        }\n\n        if (retryInterval is { } retryIntervalValue)\n        {\n            BvFlow.ValidatePositive(retryIntervalValue, nameof(retryInterval));\n        }\n    }\n\n    internal static string DescribeTargets(IReadOnlyList<BvLocator> targets, BvFlowCondition condition)\n    {","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/BgiVision/BvFlowAction.cs#L239-L275","documentation":"Thrown by DecodeImage when both the WPF BitmapDecoder and the SixLabors.ImageSharp fallback fail to decode the byte array into a valid image. The WPF path catches NotSupportedException or FileFormatException and falls back to ImageSharp; if ImageSharp also throws, an InvalidDataException wraps the ImageSharp exception. This means the bytes are not a recognizable or supported image format.","triggerScenarios":"DecodeImage receives bytes that are corrupted, truncated, or in an unsupported format. BitmapDecoder.Create throws NotSupportedException/FileFormatException (WPF can't handle it), then Image.Load<Bgra32> also throws (ImageSharp can't handle it).","commonSituations":"Downloaded image was truncated by a network error or proxy, the file is not actually an image (e.g. an HTML 404 page saved as .png), the format is exotic (e.g. HEIC, AVIF) unsupported by both decoders, or the bytes are zero-length.","solutions":["Inspect the InnerException (the ImageSharp exception) for the specific format error.","Verify the source URL/path points to a real image (open it in a browser/image viewer).","Check the first few bytes for a valid image magic number (PNG: 89 50 4E 47, JPEG: FF D8 FF).","Convert the image to PNG or JPEG before referencing it in Markdown."],"exampleFix":"// before\ncatch (Exception imageSharpException)\n{\n    throw new InvalidDataException(\"无法解码 Markdown 图片。\", imageSharpException);\n}\n\n// after — include format hint and degrade\ncatch (Exception imageSharpException)\n{\n    _owner.ReportDiagnostic(new MarkdownDiagnostic(MarkdownDiagnosticSeverity.Warning,\n        $\"无法解码图片（格式不支持或数据损坏）：{imageSharpException.Message}\"));\n    return MarkdownImageResult.Placeholder;\n}","handlingStrategy":"try-catch","validationCode":"// Pre-validate image magic number before decoding\nif (bytes.Length < 4) return Placeholder;\nvar isPng = bytes[0] == 0x89 && bytes[1] == 0x50;\nvar isJpeg = bytes[0] == 0xFF && bytes[1] == 0xD8;\nvar isGif = bytes[0] == 0x47 && bytes[1] == 0x49;\nif (!(isPng || isJpeg || isGif)) return Placeholder;","typeGuard":"static bool HasValidImageHeader(byte[] bytes) =>\n    bytes.Length >= 4 && (\n        (bytes[0] == 0x89 && bytes[1] == 0x50) || // PNG\n        (bytes[0] == 0xFF && bytes[1] == 0xD8) || // JPEG\n        (bytes[0] == 0x47 && bytes[1] == 0x49));  // GIF","tryCatchPattern":"try { return DecodeImage(bytes); }\ncatch (InvalidDataException ex) { _logger.LogWarning(ex.Inner, \"解码失败\"); return Placeholder; }","preventionTips":["Check the image magic number before attempting full decode.","Inspect the InnerException (ImageSharp) for specific format errors.","Ensure downloaded bytes are complete (verify Content-Length vs actual)."],"tags":["markdown","image","decoding","wpf","imagesharp"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}