{"record":{"id":"16ca029d769c7e18","repo":"spicetify/cli","slug":"file-is-not-in-utf-16le-format-s","errorCode":null,"errorMessage":"file is not in UTF-16LE format: %s","messagePattern":"file is not in UTF-16LE format: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utils/file-utils.go","lineNumber":31,"sourceCode":"\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}\n\n\tcontentToSearch = fileContent[2:]\n\tsearchStartMarker = encodeUTF16LE(startMarker)\n\tsearchEndMarker = encodeUTF16LE(endMarker)\n\n\tstartIdx = bytes.Index(contentToSearch, searchStartMarker)\n\tif startIdx == -1 {\n\t\treturn \"\", -1, -1, fmt.Errorf(\"start marker not found: %s\", string(startMarker))\n\t}\n\n\tsearchSpace := contentToSearch[startIdx+len(searchStartMarker):]\n\tendIdx = bytes.Index(searchSpace, searchEndMarker)\n\tif endIdx == -1 {\n\t\treturn \"\", -1, -1, fmt.Errorf(\"end marker not found after start index %d: %s\", startIdx+len(searchStartMarker), string(endMarker))\n\t}\n\n\tstringContentBytes := contentToSearch[startIdx : startIdx+len(searchStartMarker)+endIdx+len(searchEndMarker)]","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/spicetify/cli/blob/1f13f736163165234eef4fb792a03f9b5b732aa4/src/utils/file-utils.go#L13-L49","documentation":"ReadStringFromUTF16Binary requires the input file to be UTF-16LE; it checks for a BOM (0xFF 0xFE) and, if absent, refuses to scan. This error states the file is not UTF-16LE and includes the path. The function cannot safely encode/locate markers in a file of unknown or different encoding.","triggerScenarios":"Calling ReadStringFromUTF16Binary on a file lacking the 0xFF 0xFE BOM in its first two bytes — e.g. an ASCII/UTF-8 file, a UTF-16BE file (0xFE 0xFF), or a BOM-less UTF-16LE binary.","commonSituations":"Pointing the function at the wrong file (a plain-text config instead of the .bnk binary); Spotify rewrote the file without BOM in a newer version; file truncated so the first bytes are gone.","solutions":["Verify you are passing the correct binary file that is stored as UTF-16LE with BOM.","Hexdump the first two bytes; confirm FF FE. If BOM-less UTF-16LE, adjust the caller to strip/insert the BOM handling.","Regenerate the file from Spotify (reinstall/relaunch) if it was corrupted or truncated.","If the newer Spotify format dropped the BOM, use an updated helper that handles BOM-less UTF-16LE."],"exampleFix":"// before\nval, _, _, err := utils.ReadStringFromUTF16Binary(cfgPath, start, end)\n// after (wrong file — use the UTF-16LE bnk)\nval, _, _, err := utils.ReadStringFromUTF16Binary(bnkPath, start, end)","handlingStrategy":"validation","validationCode":"head := make([]byte, 2)\nf, _ := os.Open(inputFile)\nio.ReadFull(f, head)\nf.Close()\nif head[0] != 0xFF || head[1] != 0xFE {\n    return fmt.Errorf(\"%s has no UTF-16LE BOM\", inputFile)\n}","typeGuard":null,"tryCatchPattern":"val, _, _, err := utils.ReadStringFromUTF16Binary(path, start, end)\nif err != nil && strings.Contains(err.Error(), \"not in UTF-16LE format\") {\n    // pick the correct binary or handle BOM-less UTF-16LE yourself\n    return err\n}","preventionTips":["Check the BOM bytes (FF FE) before handing files to UTF-16 helpers.","Don't pass plain-text or UTF-8 files to binary UTF-16 extraction helpers.","Re-verify file format assumptions after Spotify version upgrades."],"tags":["encoding","utf16","binary"],"backgroundTag":"invalid-encoding","analyzedSha":"1f13f736163165234eef4fb792a03f9b5b732aa4","analyzedAt":"2026-08-31T18:57:59.754Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}