matryer/xbar · error

bad parameter: %s (should be paramN)

Error message

bad parameter: %s (should be paramN)

What it means

This error occurs when a param string key starts with "param" (so it is treated as a positional shell parameter) but the remainder is not a valid integer, e.g. paramx or paramfoo. setValueByKey strips the 'param' prefix and calls strconv.Atoi; on failure it reports 'bad parameter: <key> (should be paramN)'. Positional params populate p.ShellParams which are passed to the item's shell command.

Source

Thrown at pkg/plugins/item_params.go:261

			return errors.Wrap(err, key)
		}
	case "emojize":
		var err error
		p.Emojize, err = parseBool(value)
		if err != nil {
			return errors.Wrap(err, key)
		}
	case "ansi":
		var err error
		p.ANSI, err = parseBool(value)
		if err != nil {
			return errors.Wrap(err, key)
		}
	default:
		if strings.HasPrefix(key, "param") {
			paramIndex, err := strconv.Atoi(key[5:])
			if err != nil {
				return errors.Errorf("bad parameter: %s (should be paramN)", key)
			}
			for len(p.ShellParams) < paramIndex {
				// ensure the slice is big enough
				p.ShellParams = append(p.ShellParams, "")
			}
			p.ShellParams[paramIndex-1] = value
			return nil
		}
		return errors.Errorf("unknown parameter: %s", key)
	}
	return nil
}

// parseBool parses a boolean from a string (either `true` or `false`),
// returning a nice error if it fails.
func parseBool(s string) (bool, error) {
	b, err := strconv.ParseBool(s)
	if err != nil {

View on GitHub (pinned to d624239058)

Solutions

  1. Use a numeric suffix: param1=..., param2=... instead of param=... or a non-numeric suffix.
  2. Fix typos in the key (e.g. paraml1 -> param11) so the suffix parses as an integer.
  3. If you want an arbitrary named key, it is not supported — pass the value through the shell command directly or use the shell= key.
  4. Start numbering at param1; verify the emitted keys with the actual script output.

Example fix

// before
params := "param=hello"
// after
params := "param1=hello"
Defensive patterns

Strategy: validation

Validate before calling

re := regexp.MustCompile(`\bparam[0-9]+=`)
for _, kv := range strings.Split(params, ",") {
    k := strings.SplitN(kv, "=", 2)[0]
    if strings.HasPrefix(k, "param") && !regexp.MustCompile(`^param[0-9]+$`).MatchString(k) {
        return fmt.Errorf("key %q must be paramN, e.g. param1", k)
    }
}

Type guard

var paramKeyRe = regexp.MustCompile(`^param[0-9]+$`)
func isParamKey(k string) bool { return paramKeyRe.MatchString(k) }

Try / catch

if err := item.ParseParams(raw); err != nil {
    if strings.Contains(err.Error(), "bad parameter") {
        log.Printf("misnamed shell param in %q: %v", raw, err)
        return // fix the metadata line
    }
}

Prevention

When it happens

Trigger: Parsing a param string containing keys like 'param=value', 'param1a=x', 'param=foo', or 'param01text' — any key with the 'param' prefix whose suffix fails strconv.Atoi. Note param0 is accepted syntactically by Atoi but indexes ShellParams[-1] only after the loop pads the slice, so shell params should be param1, param2, ...

Common situations: Authors write 'param=value' thinking it is a named parameter syntax, or make typos like 'parm1' vs 'param1' mix-ups such as 'paraml1' (lowercase L instead of 1). Copy-paste from docs where the N in paramN was not replaced with a number.

Related errors


AI-assisted analysis of matryer/xbar@d624239058 (2026-09-02). Data as JSON: /api/errors/5e0f29c9670fe2ad. Report an issue: GitHub.