{"record":{"id":"9717142b4cff55a0","repo":"kovidgoyal/kitty","slug":"no-cache-found-and-max-cache-age-is-negative","errorCode":null,"errorMessage":"No cache found and max cache age is negative","messagePattern":"No cache found and max cache age is negative","errorType":"error_code","errorClass":"ErrNoCacheFound","httpStatus":null,"severity":"warning","filePath":"tools/themes/collection.go","lineNumber":333,"sourceCode":"\t\"selection_background\":                 true,\n\t\"selection_foreground\":                 true,\n\t\"tab_bar_background\":                   true,\n\t\"tab_bar_margin_color\":                 true,\n\t\"url_color\":                            true,\n\t\"visual_bell_color\":                    true,\n\t\"wayland_titlebar_color\":               true,\n\t\"window_title_bar_active_background\":   true,\n\t\"window_title_bar_active_foreground\":   true,\n\t\"window_title_bar_inactive_background\": true,\n\t\"window_title_bar_inactive_foreground\": true, // ALL_COLORS_END\n} // }}}\n\ntype JSONMetadata struct {\n\tEtag      string `json:\"etag\"`\n\tTimestamp string `json:\"timestamp\"`\n}\n\nvar ErrNoCacheFound = errors.New(\"No cache found and max cache age is negative\")\n\nfunc set_comment_in_zip_file(path string, comment string) error {\n\tsrc, err := zip.OpenReader(path)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer src.Close()\n\tbuf := bytes.Buffer{}\n\tdest := zip.NewWriter(&buf)\n\tif err = dest.SetComment(comment); err != nil {\n\t\treturn err\n\t}\n\tfor _, sf := range src.File {\n\t\terr = dest.Copy(sf)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/tools/themes/collection.go#L315-L351","documentation":"ErrNoCacheFound is a sentinel error in tools/themes/collection.go returned by the cached-theme paths (fetch_cached, change_colors, GetThemeNames) when no local theme cache exists AND the configured max cache age is negative — i.e. the caller forbade network fetches (cache-only mode) but there is nothing cached yet. It distinguishes 'allowed to download' from 'must use cache, cache missing'.","triggerScenarios":"Invoking theme operations (e.g. `kitten themes` in --cache-only mode, or the API's GetThemeNames/fetch_cached) with a negative max cache age (cache age < 0 means 'never hit the network') before any theme cache has been downloaded.","commonSituations":"First run of the themes kitten with network disabled/cache-only requested; CI or offline machines; deleting ~/.cache/kitty/themes then running in cache-only mode; misinterpreting the max-age API where a negative value means 'no network'.","solutions":["Allow the initial download once: run with a non-negative max cache age so the cache is populated, after which cache-only mode works","If offline, copy a prebuilt cache from another machine into the kitty themes cache directory (~/.cache/kitty/themes)","Check for this sentinel with errors.Is(err, themes.ErrNoCacheFound) and show a friendly 'run once online' message"],"exampleFix":"# before\nkitten themes --cache-age=-1   # error: No cache found and max cache age is negative\n\n# after\nkitten themes                  # once, online: populates the cache\nkitten themes --cache-age=-1   # now works offline","handlingStrategy":"fallback","validationCode":"import os\n\ncache_exists = os.path.exists(os.path.expanduser('~/.cache/kitty/themes'))\ncache_only = max_cache_age < 0\nif cache_only and not cache_exists:\n    # populate cache once with a network-allowed call before proceeding\n    ...","typeGuard":"func isNoCache(err error) bool {\n    return errors.Is(err, themes.ErrNoCacheFound)\n}","tryCatchPattern":"if err := fetch_cached(...); err != nil {\n    if errors.Is(err, themes.ErrNoCacheFound) {\n        // prompt user to run once online, or use bundled defaults\n    }\n}","preventionTips":["Run the themes kitten once online to seed the cache before enabling cache-only mode","Ship/pre-seed the cache directory on offline machines","Treat a negative max age strictly as 'no network' and preflight the cache"],"tags":["kitty","themes","cache","offline","sentinel-error","go"],"backgroundTag":"cache-miss-no-network-fallback","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}