yorukot/superfile · error

could not unmarshal user's theme file(%s) : %w

Error message

could not unmarshal user's theme file(%s) : %w

What it means

LoadUserTheme unmarshals the theme file bytes as TOML; this error wraps any toml.Unmarshal failure. It means the file was read successfully but its contents are not valid TOML or contain fields/shape incompatible with ThemeType.

Source

Thrown at src/internal/common/load_config.go:218

	// Validations
	if len(Theme.GradientColor) != RequiredGradientColorCount {
		utils.PrintlnAndExit(
			LoadThemeError(
				"gradient_color",
				"Gradient color must contain exactly two values.",
			),
		)
	}
}

func LoadUserTheme(themeFile string, obj *ThemeType) error {
	data, err := os.ReadFile(themeFile)
	if err != nil {
		return fmt.Errorf("could not read user's theme file(%s), err : %w", themeFile, err)
	}
	if err = toml.Unmarshal(data, obj); err != nil {
		return fmt.Errorf("could not unmarshal user's theme file(%s) : %w", themeFile, err)
	}
	return nil
}

// LoadAllDefaultConfig : Load all default configurations from embedded superfile_config folder into global
// configurations variables and write theme files if its needed.
func LoadAllDefaultConfig(content embed.FS) {
	err := LoadConfigStringGlobals(content)
	if err != nil {
		slog.Error("Could not load default config from embed FS", "error", err)
		return
	}

	currentThemeVersion, err := os.ReadFile(variable.ThemeFileVersion)
	if err != nil && !os.IsNotExist(err) {
		slog.Error("Unexpected error reading from file:", "error", err)
		return
	}

View on GitHub (pinned to b72f550bc6)

Solutions

  1. Validate the TOML with a TOML linter/parser (e.g. taplo) to find the syntax error.
  2. Diff the file against a working default theme file to find incompatible fields.
  3. Restore a stock theme file or re-download it.
  4. Update superfile if the theme schema changed between versions.

Example fix

// before
background = '#1e1e2e  // missing closing quote
// after
background = '#1e1e2e'
Defensive patterns

Strategy: validation

Validate before calling

data, err := os.ReadFile(themeFile)
if err != nil { return err }
var probe ThemeType
if err := toml.Unmarshal(data, &probe); err != nil {
    return fmt.Errorf("invalid theme TOML in %s: %w", themeFile, err)
}

Type guard

func isTomlSyntaxError(err error) bool {
    var parseErr toml.ParseError
    return errors.As(err, &parseErr)
}

Try / catch

if err := common.LoadUserTheme(themeFile, &theme); err != nil {
    var parseErr toml.ParseError
    if errors.As(err, &parseErr) {
        log.Errorf("Theme file %s is not valid TOML (line info: %v)", themeFile, parseErr)
        return fallbackTheme()
    }
    return err
}

Prevention

When it happens

Trigger: LoadThemeFile -> LoadUserTheme where the theme file exists but toml.Unmarshal(data, obj) fails: malformed TOML syntax, duplicate keys, or a value with the wrong type for a ThemeType field.

Common situations: Hand-edited theme file with a missing quote or unclosed table; a theme downloaded from the internet written for a different superfile version (schema changed); saving the file with wrong encoding or accidental JSON/YAML content.

Related errors


AI-assisted analysis of yorukot/superfile@b72f550bc6 (2026-09-01). Data as JSON: /api/errors/03d8914b78631f92. Report an issue: GitHub.