chenhg5/cc-connect · error

tuitui: history_limit must be non-negative

Error message

tuitui: history_limit must be non-negative

What it means

New() validates the optional "history_limit" option before constructing the Platform. The option is accepted via intOption and must be a non-negative integer because it caps how many historical messages the platform keeps/loads. A negative value is meaningless for a count, so construction fails fast with this error rather than misbehaving later.

Source

Thrown at platform/tuitui/tuitui.go:145

	groupPolicy = strings.ToLower(strings.TrimSpace(groupPolicy))
	switch groupPolicy {
	case "allowlist", "open", "disabled":
	default:
		return nil, fmt.Errorf("tuitui: invalid group_policy %q (want allowlist, open, or disabled)", groupPolicy)
	}
	requireMention := true
	if v, ok := opts["require_mention"].(bool); ok {
		requireMention = v
	}
	receiveReaction := "收到"
	if v, ok := opts["receive_reaction"].(string); ok {
		receiveReaction = strings.TrimSpace(v)
	}
	shareSessionInChannel, _ := opts["share_session_in_channel"].(bool)
	pendingHistoryLimit := defaultHistoryLimit
	if v, ok := intOption(opts["history_limit"]); ok {
		if v < 0 {
			return nil, fmt.Errorf("tuitui: history_limit must be non-negative")
		}
		pendingHistoryLimit = v
	}

	return &Platform{
		appID:                 appID,
		appSecret:             appSecret,
		apiBase:               strings.TrimRight(apiBase, "/"),
		wsBase:                strings.TrimRight(wsBase, "/"),
		allowFrom:             allowFrom,
		groupAllowFrom:        groupAllowFrom,
		ignoreFrom:            ignoreFrom,
		groupPolicy:           groupPolicy,
		receiveReaction:       receiveReaction,
		requireMention:        requireMention,
		shareSessionInChannel: shareSessionInChannel,
		pendingHistoryLimit:   pendingHistoryLimit,
		client:                &http.Client{Timeout: httpTimeout},

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Set "history_limit" to a non-negative integer in the platform options/config (or remove the key to use defaultHistoryLimit).
  2. If the intent was to disable history, omit the "history_limit" option entirely instead of passing a negative number.
  3. Clamp or validate the value at the config-loading layer before calling New.

Example fix

// before
opts["history_limit"] = -1
p, err := tuitui.New(opts)
// after
opts["history_limit"] = 0 // or omit the key to use the default
p, err := tuitui.New(opts)
Defensive patterns

Strategy: validation

Validate before calling

if v, ok := opts["history_limit"].(int); ok && v < 0 {
    return fmt.Errorf("history_limit must be >= 0, got %d", v)
}

Type guard

func validHistoryLimit(v int) bool { return v >= 0 }

Prevention

When it happens

Trigger: Calling tuitui.New (directly or via loadTuiTuiPlatform / core.CreatePlatform) with opts containing "history_limit" set to a negative integer such as -1, or a negative value loaded from config.toml.

Common situations: Config typo where a user writes history_limit = -1 thinking it disables history tracking; a script computing the limit from a difference that went negative; environment/config templating substituting an empty or sentinel value that parses to a negative number.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/db77a8a4ebb5b5d8. Report an issue: GitHub.