larksuite/cli · error

invalid risk %q: must be read|write|high-risk-write

Error message

invalid risk %q: must be read|write|high-risk-write

What it means

ParseRisk in extension/platform only accepts "read", "write", or "high-risk-write" (or empty, meaning unset), checked against the riskOrder map. Any other string is rejected because Risk is a closed three-level enum used to declare plugin command risk.

Source

Thrown at extension/platform/risk.go:51

//   - s == ""        → ("", nil)            "not specified"
//   - s 在闭合枚举   → (Risk(s), nil)       OK
//   - s 不在枚举内   → ("", error)          invalid
//
// The (absent vs invalid) split mirrors the cmdpolicy engine's
// risk_not_annotated vs risk_invalid reason codes — callers can treat
// the "" + nil case as "not specified" without losing the distinction
// from a typo.
//
// Matching is strict: "Read" / "READ" / " read " are all rejected.
// annotation is developer code, not user input — strict matching is
// the typo-catch mechanism, not a normalisation opportunity.
func ParseRisk(s string) (Risk, error) {
	if s == "" {
		return "", nil
	}
	r := Risk(s)
	if _, ok := riskOrder[r]; !ok {
		return "", fmt.Errorf("invalid risk %q: must be read|write|high-risk-write", s)
	}
	return r, nil
}

// IsValid reports whether r is one of the three recognised values.
func (r Risk) IsValid() bool {
	_, ok := riskOrder[r]
	return ok
}

// Rank returns the comparable rank of r. ok=false when r is not in the
// closed taxonomy.
func (r Risk) Rank() (rank int, ok bool) {
	rank, ok = riskOrder[r]
	return rank, ok
}

// String returns the underlying string. Useful for yaml/json output

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Use exactly one of "read", "write", "high-risk-write" (lowercase, hyphenated)
  2. Validate with Risk(s).IsValid() before parsing in a pipeline
  3. Normalize/trim input, ensuring hyphens not underscores
  4. Leave empty if risk should be defaulted later

Example fix

// before
r, err := platform.ParseRisk("high_risk_write")
// after
r, err := platform.ParseRisk("high-risk-write")
Defensive patterns

Strategy: validation

Validate before calling

var riskValues = map[string]bool{"read": true, "write": true, "high-risk-write": true}
func validRisk(s string) bool { return s == "" || riskValues[s] }
r, err := platform.ParseRisk(strings.ToLower(strings.TrimSpace(cfg.Risk)))

Type guard

func isRisk(s string) bool { switch s { case "", "read", "write", "high-risk-write": return true }; return false }

Try / catch

r, err := platform.ParseRisk(s)
if err != nil { return fmt.Errorf("manifest risk: %w", err) }

Prevention

When it happens

Trigger: Calling ParseRisk with values like "readonly", "rw", "dangerous", "high", or capitalized "Read".

Common situations: Manifests/configs authored with free-form risk labels; migrating from another tool's risk vocabulary; typos such as "high_risk_write".

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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