spicetify/cli · error

error reading file %s: %w

Error message

error reading file %s: %w

What it means

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.

Source

Thrown at src/utils/file-utils.go:14

package utils

import (
	"bytes"
	"encoding/binary"
	"fmt"
	"os"
	"unicode/utf16"
)

func ReadStringFromUTF16Binary(inputFile string, startMarker []byte, endMarker []byte) (string, int, int, error) {
	fileContent, err := os.ReadFile(inputFile)
	if err != nil {
		return "", -1, -1, fmt.Errorf("error reading file %s: %w", inputFile, err)
	}

	isUTF16LE := false
	if len(fileContent) >= 2 && fileContent[0] == 0xFF && fileContent[1] == 0xFE {
		isUTF16LE = true
	}

	if !isUTF16LE && len(fileContent) > 100 && fileContent[1] == 0x00 {
		isUTF16LE = true
	}

	var startIdx, endIdx int
	var contentToSearch []byte
	var searchStartMarker, searchEndMarker []byte

	if !isUTF16LE {
		return "", -1, -1, fmt.Errorf("file is not in UTF-16LE format: %s", inputFile)
	}

View on GitHub (pinned to 1f13f73616)

Solutions

  1. Confirm the inputFile path exists and is spelled correctly (check with ls/stat).
  2. Fix read permissions on the file/directory for the current user.
  3. Close Spotify or other processes holding the file exclusively, then retry.
  4. Regenerate the file (reinstall/relaunch Spotify) if it was removed by an update.

Example fix

// before
s, _, _, err := utils.ReadStringFromUTF16Binary(bnkPath, start, end)
// after
if _, statErr := os.Stat(bnkPath); statErr != nil {
    utils.Fatal(fmt.Errorf("bnk path bad: %w", statErr))
}
s, _, _, err := utils.ReadStringFromUTF16Binary(bnkPath, start, end)
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(inputFile); err != nil {
    return fmt.Errorf("input file missing/unreadable: %w", err)
}

Try / catch

val, _, _, err := utils.ReadStringFromUTF16Binary(path, start, end)
if err != nil {
    var pathErr *fs.PathError
    if errors.As(err, &pathErr) {
        // correct path / permissions / close holding process
    }
    return err
}

Prevention

When it happens

Trigger: Calling ReadStringFromUTF16Binary(inputFile, ...) where inputFile does not exist, is unreadable (permissions), or is locked/unopenable by the OS.

Common situations: 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.

Related errors


AI-assisted analysis of spicetify/cli@1f13f73616 (2026-08-31). Data as JSON: /api/errors/4e38efe1713d686c. Report an issue: GitHub.