{"record":{"id":"03d8914b78631f92","repo":"yorukot/superfile","slug":"could-not-unmarshal-user-s-theme-file-s-w","errorCode":null,"errorMessage":"could not unmarshal user's theme file(%s) : %w","messagePattern":"could not unmarshal user's theme file\\((.+?)\\) : %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/internal/common/load_config.go","lineNumber":218,"sourceCode":"\n\t// Validations\n\tif len(Theme.GradientColor) != RequiredGradientColorCount {\n\t\tutils.PrintlnAndExit(\n\t\t\tLoadThemeError(\n\t\t\t\t\"gradient_color\",\n\t\t\t\t\"Gradient color must contain exactly two values.\",\n\t\t\t),\n\t\t)\n\t}\n}\n\nfunc LoadUserTheme(themeFile string, obj *ThemeType) error {\n\tdata, err := os.ReadFile(themeFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not read user's theme file(%s), err : %w\", themeFile, err)\n\t}\n\tif err = toml.Unmarshal(data, obj); err != nil {\n\t\treturn fmt.Errorf(\"could not unmarshal user's theme file(%s) : %w\", themeFile, err)\n\t}\n\treturn nil\n}\n\n// LoadAllDefaultConfig : Load all default configurations from embedded superfile_config folder into global\n// configurations variables and write theme files if its needed.\nfunc LoadAllDefaultConfig(content embed.FS) {\n\terr := LoadConfigStringGlobals(content)\n\tif err != nil {\n\t\tslog.Error(\"Could not load default config from embed FS\", \"error\", err)\n\t\treturn\n\t}\n\n\tcurrentThemeVersion, err := os.ReadFile(variable.ThemeFileVersion)\n\tif err != nil && !os.IsNotExist(err) {\n\t\tslog.Error(\"Unexpected error reading from file:\", \"error\", err)\n\t\treturn\n\t}","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/internal/common/load_config.go#L200-L236","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Validate the TOML with a TOML linter/parser (e.g. taplo) to find the syntax error.","Diff the file against a working default theme file to find incompatible fields.","Restore a stock theme file or re-download it.","Update superfile if the theme schema changed between versions."],"exampleFix":"// before\nbackground = '#1e1e2e  // missing closing quote\n// after\nbackground = '#1e1e2e'","handlingStrategy":"validation","validationCode":"data, err := os.ReadFile(themeFile)\nif err != nil { return err }\nvar probe ThemeType\nif err := toml.Unmarshal(data, &probe); err != nil {\n    return fmt.Errorf(\"invalid theme TOML in %s: %w\", themeFile, err)\n}","typeGuard":"func isTomlSyntaxError(err error) bool {\n    var parseErr toml.ParseError\n    return errors.As(err, &parseErr)\n}","tryCatchPattern":"if err := common.LoadUserTheme(themeFile, &theme); err != nil {\n    var parseErr toml.ParseError\n    if errors.As(err, &parseErr) {\n        log.Errorf(\"Theme file %s is not valid TOML (line info: %v)\", themeFile, parseErr)\n        return fallbackTheme()\n    }\n    return err\n}","preventionTips":["Validate hand-edited theme files with a TOML linter before deploying.","Pin theme files to the superfile version that understands their schema.","Keep a known-good stock theme as a fallback.","Avoid copy-pasting theme snippets from YAML/JSON into TOML files."],"tags":["config","theme","toml","parsing"],"backgroundTag":"toml-parse-error","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}