{"record":{"id":"4e38efe1713d686c","repo":"spicetify/cli","slug":"error-reading-file-s-w","errorCode":null,"errorMessage":"error reading file %s: %w","messagePattern":"error reading file (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utils/file-utils.go","lineNumber":14,"sourceCode":"package utils\n\nimport (\n\t\"bytes\"\n\t\"encoding/binary\"\n\t\"fmt\"\n\t\"os\"\n\t\"unicode/utf16\"\n)\n\nfunc ReadStringFromUTF16Binary(inputFile string, startMarker []byte, endMarker []byte) (string, int, int, error) {\n\tfileContent, err := os.ReadFile(inputFile)\n\tif err != nil {\n\t\treturn \"\", -1, -1, fmt.Errorf(\"error reading file %s: %w\", inputFile, err)\n\t}\n\n\tisUTF16LE := false\n\tif len(fileContent) >= 2 && fileContent[0] == 0xFF && fileContent[1] == 0xFE {\n\t\tisUTF16LE = true\n\t}\n\n\tif !isUTF16LE && len(fileContent) > 100 && fileContent[1] == 0x00 {\n\t\tisUTF16LE = true\n\t}\n\n\tvar startIdx, endIdx int\n\tvar contentToSearch []byte\n\tvar searchStartMarker, searchEndMarker []byte\n\n\tif !isUTF16LE {\n\t\treturn \"\", -1, -1, fmt.Errorf(\"file is not in UTF-16LE format: %s\", inputFile)\n\t}","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/spicetify/cli/blob/1f13f736163165234eef4fb792a03f9b5b732aa4/src/utils/file-utils.go#L1-L32","documentation":"ReadStringFromUTF16Binary reads a binary file to extract a string delimited by UTF-16LE start/end markers. This error wraps any os.ReadFile failure on the input file with the file path and underlying cause. It fires before any marker scanning happens.","triggerScenarios":"Calling ReadStringFromUTF16Binary(inputFile, ...) where inputFile does not exist, is unreadable (permissions), or is locked/unopenable by the OS.","commonSituations":"Wrong path to Spotify's data file (offline.bnk etc.); file held by another process or missing after a Spotify update; running without permissions in the Spotify profile directory; typo in the config-driven path.","solutions":["Confirm the inputFile path exists and is spelled correctly (check with ls/stat).","Fix read permissions on the file/directory for the current user.","Close Spotify or other processes holding the file exclusively, then retry.","Regenerate the file (reinstall/relaunch Spotify) if it was removed by an update."],"exampleFix":"// before\ns, _, _, err := utils.ReadStringFromUTF16Binary(bnkPath, start, end)\n// after\nif _, statErr := os.Stat(bnkPath); statErr != nil {\n    utils.Fatal(fmt.Errorf(\"bnk path bad: %w\", statErr))\n}\ns, _, _, err := utils.ReadStringFromUTF16Binary(bnkPath, start, end)","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(inputFile); err != nil {\n    return fmt.Errorf(\"input file missing/unreadable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"val, _, _, err := utils.ReadStringFromUTF16Binary(path, start, end)\nif err != nil {\n    var pathErr *fs.PathError\n    if errors.As(err, &pathErr) {\n        // correct path / permissions / close holding process\n    }\n    return err\n}","preventionTips":["Resolve the file path from Spotify's actual install/profile location, not hardcoded guesses.","Stat the file before parsing to fail with a clearer message.","Re-validate paths after Spotify updates, which can move or remove data files."],"tags":["filesystem","utf16","binary"],"backgroundTag":"file-read-failed","analyzedSha":"1f13f736163165234eef4fb792a03f9b5b732aa4","analyzedAt":"2026-08-31T18:57:59.754Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}