{
  "id": "flutter/formatexception-invalid-utf8-byte-sequence",
  "signature": "FormatException: Invalid UTF-8 byte sequence",
  "signature_zh": "FormatException：无效的 UTF-8 字节序列",
  "regex": "FormatException: Invalid UTF-8 byte sequence",
  "domain": "flutter",
  "category": "encoding_error",
  "subcategory": null,
  "root_cause": "Data received from network or file is not valid UTF-8 encoded, causing Dart's utf8 decoder to fail.",
  "root_cause_type": "generic",
  "root_cause_zh": "从网络或文件接收的数据不是有效的 UTF-8 编码，导致 Dart 的 utf8 解码器失败。",
  "versions": [
    {
      "version": "Flutter 3.7",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Flutter 3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Flutter 3.13",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Ignoring the error and assuming data is always valid UTF-8",
      "why_fails": "The error will reappear whenever malformed data is encountered; no resilience.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using utf8.decode(bytes, allowMalformed: true) without logging",
      "why_fails": "Silently replaces invalid sequences with replacement characters, potentially corrupting data silently.",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    },
    {
      "action": "Assuming the data source will always send correct UTF-8",
      "why_fails": "External data sources (especially user input or legacy systems) often send non-UTF-8 encodings like Latin-1.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Detect encoding first using package like 'charset' or 'universal_io' and decode with correct encoding:\nimport 'dart:convert';\nimport 'package:charset/charset.dart';\n\nList<int> bytes = ...;\nString text;\ntry {\n  text = utf8.decode(bytes);\n} on FormatException {\n  text = latin1.decode(bytes); // fallback\n}",
      "success_rate": 0.88,
      "how": "Detect encoding first using package like 'charset' or 'universal_io' and decode with correct encoding:\nimport 'dart:convert';\nimport 'package:charset/charset.dart';\n\nList<int> bytes = ...;\nString text;\ntry {\n  text = utf8.decode(bytes);\n} on FormatException {\n  text = latin1.decode(bytes); // fallback\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use utf8.decode(bytes, allowMalformed: true) and then sanitize or log replacement characters for debugging:\nString text = utf8.decode(bytes, allowMalformed: true);\nif (text.contains('\\uFFFD')) { print('Malformed data detected'); }",
      "success_rate": 0.85,
      "how": "Use utf8.decode(bytes, allowMalformed: true) and then sanitize or log replacement characters for debugging:\nString text = utf8.decode(bytes, allowMalformed: true);\nif (text.contains('\\uFFFD')) { print('Malformed data detected'); }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Before decoding, validate bytes with a BOM (Byte Order Mark) or use a library like 'chardet' to auto-detect encoding.",
      "success_rate": 0.9,
      "how": "Before decoding, validate bytes with a BOM (Byte Order Mark) or use a library like 'chardet' to auto-detect encoding.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Detect encoding first using package like 'charset' or 'universal_io' and decode with correct encoding:\nimport 'dart:convert';\nimport 'package:charset/charset.dart';\n\nList<int> bytes = ...;\nString text;\ntry {\n  text = utf8.decode(bytes);\n} on FormatException {\n  text = latin1.decode(bytes); // fallback\n}",
    "Use utf8.decode(bytes, allowMalformed: true) and then sanitize or log replacement characters for debugging:\nString text = utf8.decode(bytes, allowMalformed: true);\nif (text.contains('\\uFFFD')) { print('Malformed data detected'); }",
    "Before decoding, validate bytes with a BOM (Byte Order Mark) or use a library like 'chardet' to auto-detect encoding."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://api.dart.dev/stable/dart-convert/Utf8Decoder-class.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-06-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}