mirror of
https://github.com/larksuite/cli.git
synced 2026-07-03 22:24:31 +08:00
Replace every command-facing error path in the event domain — the consume/schema command layer, the +subscribe shortcut, EventKey definitions, and the consume orchestration — with typed errs.* envelopes, so consumers get stable type, subtype, param, hint, and missing_scopes metadata for classification and recovery instead of free-form message text. - Input validation (--jq, --param, --output-dir, --filter, --route, unknown EventKey, EventKey params) reports validation / invalid_argument with the offending flag in param and an actionable hint. - Scope preflight reports authorization / missing_scope with the machine-readable missing_scopes list; console-subscription and single-bus preconditions report failed_precondition with recovery hints. - The consume API boundary passes already-typed errors through and classifies transport, non-JSON HTTP, and unparsable responses; the vc note-detail retry now matches the not-found code on typed errors (it silently never fired against the legacy envelope shape). - Previously-bare failures exited 1 with a plain-text "Error:" line and now exit with their category code (validation 2, auth 3, network 4, internal 5) alongside the typed stderr envelope. - forbidigo and errscontract guards now cover the event paths so regressions fail lint; AGENTS.md and the lark-event skill document the typed contract for agent consumers. Validation: make unit-test (race) green; event unit and e2e suites assert category/subtype/param/hint and cause preservation against the real binary; errscontract and golangci lint clean.
33 lines
1.3 KiB
Go
33 lines
1.3 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package event
|
|
|
|
import "github.com/larksuite/cli/errs"
|
|
|
|
func eventValidationError(format string, args ...any) *errs.ValidationError {
|
|
return errs.NewValidationError(errs.SubtypeInvalidArgument, format, args...)
|
|
}
|
|
|
|
func eventValidationParamError(param, format string, args ...any) *errs.ValidationError {
|
|
return eventValidationError(format, args...).WithParam(param)
|
|
}
|
|
|
|
// eventValidationParamErrorWithCause appends ": <err>" to the formatted
|
|
// message and preserves err as the unwrap cause.
|
|
func eventValidationParamErrorWithCause(err error, param, format string, args ...any) *errs.ValidationError {
|
|
return eventValidationParamError(param, format+": %s", append(args, err)...).WithCause(err)
|
|
}
|
|
|
|
// eventFileIOError appends ": <err>" to the formatted message and preserves
|
|
// err as the unwrap cause.
|
|
func eventFileIOError(err error, format string, args ...any) *errs.InternalError {
|
|
return errs.NewInternalError(errs.SubtypeFileIO, format+": %s", append(args, err)...).WithCause(err)
|
|
}
|
|
|
|
// eventNetworkError appends ": <err>" to the formatted message and preserves
|
|
// err as the unwrap cause.
|
|
func eventNetworkError(err error, format string, args ...any) *errs.NetworkError {
|
|
return errs.NewNetworkError(errs.SubtypeNetworkTransport, format+": %s", append(args, err)...).WithCause(err)
|
|
}
|