{"record":{"id":"5710be1dcd127418","repo":"MiniMax-AI/skills","slug":"cannot-decode-file-path-tried-encodings-encod","errorCode":null,"errorMessage":"Cannot decode {file_path}. Tried encodings: {encodings}. Last error: {last_error}","messagePattern":"Cannot decode (.+?)\\. Tried encodings: (.+?)\\. Last error: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"skills/minimax-xlsx/scripts/xlsx_reader.py","lineNumber":72,"sourceCode":"        if isinstance(result, dict):\n            return result\n        else:\n            return {sheet_name_filter: result}\n\n    elif suffix in (\".csv\", \".tsv\"):\n        sep = \"\\t\" if suffix == \".tsv\" else \",\"\n        encodings = [\"utf-8-sig\", \"gbk\", \"utf-8\", \"latin-1\"]\n        last_error = None\n        for enc in encodings:\n            try:\n                import pandas as pd\n                df = pd.read_csv(file_path, sep=sep, encoding=enc)\n                df._reader_encoding = enc  # attach metadata (non-standard, for reporting)\n                return {path.stem: df}\n            except (UnicodeDecodeError, Exception) as e:\n                last_error = e\n                continue\n        raise ValueError(\n            f\"Cannot decode {file_path}. Tried encodings: {encodings}. \"\n            f\"Last error: {last_error}\"\n        )\n\n    elif suffix == \".xls\":\n        raise ValueError(\n            \".xls is a legacy binary format not supported by this tool. \"\n            \"Please open the file in Excel and save as .xlsx, then retry.\"\n        )\n\n    else:\n        raise ValueError(\n            f\"Unsupported file format: {suffix}. \"\n            \"Supported formats: .xlsx, .xlsm, .csv, .tsv\"\n        )\n\n\n# ---------------------------------------------------------------------------","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/minimax-xlsx/scripts/xlsx_reader.py#L54-L90","documentation":"For CSV/TSV the loader tries utf-8-sig, gbk, utf-8, latin-1 in order and, if all raise, gives up with ValueError listing the attempts and the last error. Subtlety: latin-1 maps every byte to a character and never raises UnicodeDecodeError, so a pure encoding failure is nearly impossible to reach — the real trigger is a non-encoding parser error (empty file, malformed CSV, embedded null bytes) caught by the broad 'Exception' in the except tuple.","triggerScenarios":"CSV/TSV where pd.read_csv raises under every tried encoding. Given latin-1 always decodes, this is almost always a parser error (empty file, wrong delimiter, binary/corrupt bytes, null bytes) rather than a true encoding failure.","commonSituations":"Empty or zero-byte CSV; tab-delimited content passed as .csv; file with embedded NUL bytes; corrupt/truncated export; pd.read_csv parser error on malformed quoting.","solutions":["Confirm the file is non-empty and actually CSV/TSV (check delimiter vs extension).","Re-save the file as UTF-8 from a spreadsheet editor.","Extend the encodings list with 'big5','shift_jis','utf-16' if it is genuinely a CJK/UTF-16 file.","Use chardet to detect encoding, then re-run with the detected value."],"exampleFix":"# before\nsheets = detect_and_load('data.tsv')   # ValueError: Cannot decode ...\n\n# after - extend the tried encodings and surface parser errors distinctly\nencodings = ['utf-8-sig','gbk','utf-8','big5','shift_jis','utf-16','latin-1']\nfor enc in encodings:\n    try:\n        df = pd.read_csv(path, sep=sep, encoding=enc)\n        return {Path(path).stem: df}\n    except UnicodeDecodeError:\n        continue\n    except Exception as e:\n        raise ValueError(f'parser error ({enc}): {e}') from e","handlingStrategy":"fallback","validationCode":"from pathlib import Path\np = Path(file_path)\nif p.stat().st_size == 0:\n    raise ValueError(f'{file_path} is empty')\n# sniff delimiter vs extension\nimport csv\nwith open(file_path, newline='', encoding='utf-8', errors='replace') as fh:\n    sample = fh.read(2048)\n    delim = csv.Sniffer().sniff(sample).delimiter","typeGuard":null,"tryCatchPattern":"try:\n    sheets = detect_and_load(file_path)\nexcept ValueError as e:\n    if 'Cannot decode' in str(e):\n        # fallback: let pandas autodetect, or convert via chardet\n        import chardet\n        raw = open(file_path,'rb').read()\n        enc = chardet.detect(raw)['encoding'] or 'utf-8'\n        sheets = {Path(file_path).stem: pd.read_csv(file_path, encoding=enc)}\n    else:\n        raise","preventionTips":["Pre-check that the file is non-empty before decoding.","Add big5/shift_jis/utf-16 to the encoding list for CJK/UTF-16 sources.","Use chardet as a fallback detector when the fixed list fails."],"tags":["encoding","csv","pandas","i18n"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}