kovidgoyal/kitty · error

%s is not a valid glob pattern with error: %w

Error message

%s is not a valid glob pattern with error: %w

What it means

resolve_file_spec expands a copy-instruction file spec with doublestar.FilepathGlob when it contains glob metacharacters. If the pattern is malformed (e.g. unbalanced '['), doublestar returns an error which is wrapped with the spec.

Source

Thrown at kittens/ssh/config.go:182

	}
	ans = []*EnvInstruction{ei}
	return
}

var paths_ctx *paths.Ctx

func resolve_file_spec(spec string, is_glob bool) ([]string, error) {
	if paths_ctx == nil {
		paths_ctx = &paths.Ctx{}
	}
	ans := os.ExpandEnv(paths_ctx.ExpandHome(spec))
	if !filepath.IsAbs(ans) {
		ans = paths_ctx.AbspathFromHome(ans)
	}
	if is_glob {
		files, err := doublestar.FilepathGlob(ans)
		if err != nil {
			return nil, fmt.Errorf("%s is not a valid glob pattern with error: %w", spec, err)
		}
		if len(files) == 0 {
			return nil, fmt.Errorf("%s matches no files", spec)
		}
		return files, nil
	}
	err := unix.Access(ans, unix.R_OK)
	if err != nil {
		if errors.Is(err, os.ErrNotExist) {
			return nil, fmt.Errorf("%s does not exist", spec)
		}
		return nil, fmt.Errorf("Cannot read from: %s with error: %w", spec, err)
	}
	return []string{ans}, nil
}

func get_arcname(loc, dest, home string) (arcname string) {
	if dest != "" {

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Fix the glob pattern syntax (balanced brackets, valid character classes)
  2. Escape literal metacharacters if the filename really contains them
  3. Test the pattern with a glob tester before putting it in config

Example fix

// before
copy: ~/logs/[2024-
// after
copy: ~/logs/2024-*
Defensive patterns

Strategy: validation

Validate before calling

if _, err := doublestar.FilepathGlob(pattern); err != nil { /* reject pattern before config load */ }

Type guard

func isValidGlob(p string) bool { _, err := doublestar.FilepathGlob(p); return err == nil }

Prevention

When it happens

Trigger: A copy: or env copy spec like '~/data/[a-' where the glob syntax itself is invalid.

Common situations: Windows-style paths with brackets, typos in character classes, or accidentally treating a literal filename containing '*' or '[' as a glob.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/71a5c43b5b6d4a03. Report an issue: GitHub.