larksuite/cli · error

invalid --param format

Error message

invalid --param format

What it means

errInvalidParamFormat is a sentinel error in cmd/event/consume.go for the --param flag of the event consume command. parseParams wraps it as a typed errs.ValidationError (SubtypeInvalidArgument, param --param) when an entry lacks a 'key=value' form or has an empty key. The sentinel exists so callers/tests can use errors.Is against the typed error's cause.

Source

Thrown at cmd/event/consume.go:449

	result, err := f.Credential.ResolveToken(ctx, credential.NewTokenSpec(core.AsBot, appID))
	if err != nil {
		if _, ok := errs.ProblemOf(err); ok {
			return "", err
		}
		return "", errs.NewAuthenticationError(errs.SubtypeTokenMissing,
			"resolve tenant access token: %s", err).WithCause(err)
	}
	if result == nil || result.Token == "" {
		return "", errs.NewAuthenticationError(errs.SubtypeTokenMissing,
			"no tenant access token available for app %s", appID).
			WithHint("check that app_secret is configured for this distribution")
	}
	return result.Token, nil
}

// Sentinels for errors.Is checks; call sites wrap them as typed ValidationError causes.
var (
	errInvalidParamFormat = errors.New("invalid --param format") //nolint:forbidigo // sentinel, typed at call sites
	errOutputDirUnsafe    = errors.New("unsafe --output-dir")    //nolint:forbidigo // sentinel, typed at call sites
)

func parseParams(raw []string) (map[string]string, error) {
	m := make(map[string]string)
	for _, kv := range raw {
		k, v, ok := strings.Cut(kv, "=")
		if !ok || k == "" {
			return nil, errs.NewValidationError(errs.SubtypeInvalidArgument,
				"%s %q: expected key=value", errInvalidParamFormat, kv).
				WithParam("--param").
				WithCause(errInvalidParamFormat)
		}
		m[k] = v
	}
	return m, nil
}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Pass each parameter as --param key=value with a non-empty key.
  2. Check shell quoting so the '=' survives (quote the whole 'key=value' argument).
  3. Inspect the %q message to see exactly which raw entry failed.
  4. In scripts, validate entries with a cut/grep on '=' before invoking the CLI.

Example fix

// before
lark event consume --param eventId
// after
lark event consume --param eventId=123
Defensive patterns

Strategy: validation

Validate before calling

// shell pre-validation before invoking the CLI
for p in "$params[@]"; do
  case "$p" in
    *=*) key="${p%%=*}"; [ -n "$key" ] || { echo "bad --param: $p"; exit 1; } ;;
    *)   echo "bad --param (missing =): $p"; exit 1 ;;
  esac
done

Type guard

func isValidParam(kv string) bool {
	k, _, ok := strings.Cut(kv, "=")
	return ok && k != ""
}

Try / catch

// Go caller of parseParams
params, err := parseParams(raw)
if err != nil {
	var verr *errs.ValidationError
	if errors.As(err, &verr) && errors.Is(err, errInvalidParamFormat) {
		// reprompt / fix the offending --param entry
	}
	return err
}

Prevention

When it happens

Trigger: Running the event consume command with --param entries like 'foo' (no '='), '=bar' (empty key), or empty strings; parseParams returns the sentinel and call sites emit the typed validation error.

Common situations: Shell quoting mishaps where '=' or value parts are lost; copy-pasted flags missing '='; scripting that builds --param from a list not validated for key=value shape.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/5320dc9d1bfe24da. Report an issue: GitHub.