{"record":{"id":"351b5e8a3b34a4ba","repo":"juicedata/juicefs","slug":"binary-mode-doesn-t-take-an-errors-argument","errorCode":null,"errorMessage":"binary mode doesn't take an errors argument","messagePattern":"binary mode doesn't take an errors argument","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdk/python/juicefs/juicefs/juicefs.py","lineNumber":227,"sourceCode":"            if c in 'rwxa':\n                cnt += 1\n                if c == 'r':\n                    flag |= MODE_READ\n                else:\n                    flag |= MODE_WRITE\n            elif c == '+':\n                flag |= MODE_READ | MODE_WRITE\n            elif c not in 'tb':\n                raise ValueError(f'invalid mode: {mode}')\n        if cnt != 1:\n            raise ValueError('must have exactly one of create/read/write/append mode')\n        if 'b' in mode:\n            if 't' in mode:\n                raise ValueError(\"can't have text and binary mode at once\")\n            if encoding:\n                raise ValueError(\"binary mode doesn't take an encoding argument\")\n            if errors:\n                raise ValueError(\"binary mode doesn't take an errors argument\")\n        else:\n            if not encoding:\n                encoding = locale.getpreferredencoding(False).lower()\n            if not errors:\n                errors = 'strict'\n            codecs.lookup(encoding)\n\n        size = 0\n        if 'x' in mode:\n            fd = self.lib.jfs_create(c_int64(_tid()), c_int64(self.h), _bin(path), c_uint16(0o666), c_uint16(self.umask))\n        else:\n            try:\n                sz = c_uint64()\n                fd = self.lib.jfs_open_posix(c_int64(_tid()), c_int64(self.h), _bin(path), byref(sz), c_int32(flag))\n                if 'w' in mode:\n                    self.lib.jfs_ftruncate(c_int64(_tid()), fd, c_uint64(0))\n                else:\n                    size = sz.value","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/sdk/python/juicefs/juicefs/juicefs.py#L209-L245","documentation":"juicefs.open() mimics Python's built-in open(). When the mode contains 'b' (binary), text-layer parameters like encoding and errors are meaningless, so the library raises ValueError('binary mode doesn't take an errors argument') when a non-falsy errors argument is passed together with binary mode.","triggerScenarios":"Calling juicefs.open(path, 'rb', errors='ignore'), or opening with any mode containing 'b' while supplying a truthy errors value (including errors=None is fine, but '' / 'strict' / 'ignore' trigger it).","commonSituations":"Porting code from text mode to binary mode after decoding issues; copy-pasting open(path, 'rb', errors='replace') from text-mode examples; wrapping a generic file-open helper that always forwards errors.","solutions":["Remove the errors argument when opening in binary mode","Switch to text mode ('r'/'rt') if you need errors handling","Handle decoding errors explicitly after reading bytes (data.decode('utf-8', errors='ignore'))"],"exampleFix":"// before\nf = juicefs.open('/mnt/jfs/file', 'rb', errors='ignore')\n// after\nf = juicefs.open('/mnt/jfs/file', 'rb')\n# or for text handling:\nf = juicefs.open('/mnt/jfs/file', 'r', errors='ignore')","handlingStrategy":"validation","validationCode":"if 'b' in mode and errors:\n    raise ValueError('pass errors only in text mode')","typeGuard":"def is_binary_mode(mode: str) -> bool:\n    return 'b' in mode","tryCatchPattern":null,"preventionTips":["Never pass encoding/errors with binary modes","Centralize file-open helpers to normalize arguments"],"tags":["python","valueerror","file-open","binary-mode"],"backgroundTag":"invalid-argument-value","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}