mirror of
https://github.com/larksuite/cli.git
synced 2026-07-03 14:02:43 +08:00
Introduce a typed error contract framework for lark-cli so in-process
Go callers can branch via errors.As(&errs.XxxError{}) and shell scripts,
AI agents, and protocol adapters can branch on stable JSON type/subtype
fields instead of regex-parsing free-form messages.
Adds:
- Canonical taxonomy under errs/ (9 categories + typed Error structs
embedding a shared Problem, RFC 7807-aligned)
- Centralized Lark code metadata + identity-aware BuildAPIError dispatch
- Typed JSON envelope writer alongside the legacy envelope writer
- MCP / OAuth (RFC 6750 Bearer) projection adapters
- Five CI lint guards preventing ad-hoc taxonomy drift
Backward compatibility: legacy *output.ExitError producers (ErrAPI,
ErrWithHint, Errorf, ErrBare) and business shortcuts that use them
continue to render the legacy envelope unchanged. SecurityPolicyError
wire format and exit code are preserved via a carve-out; taxonomy
migration is deferred to PR 2. Domain-specific business migration is
staged across PR 3+.
Framework-direct paths now return typed *errs.*Error: ErrAuth /
ErrValidation / ErrNetwork emit category literals on the wire
(authentication / validation / network), *core.ConfigError is promoted
at the cmd/root boundary with exit code aligned from 2 to 3, and Lark
API permission denials classified by BuildAPIError exit 3.
At the SDK boundary, WrapDoAPIError preserves any already-classified
error (legacy *output.ExitError or typed *errs.*) so output.ErrAuth
from missing credentials surfaces with the auth category and exit 3
intact instead of being downgraded to a network error. Policy responses
classified by BuildAPIError (codes 21000 / 21001) extract challenge_url
and the canonical hint from the response body, matching what the
auth transport already surfaces at the HTTP layer; non-https
challenge URLs are dropped.
First PR in the feat/error-contract-* series.
33 lines
1.2 KiB
Go
33 lines
1.2 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// Package errcompat bridges the legacy *core.ConfigError shape into the
|
|
// canonical typed errors taxonomy in errs/. It is a thin boundary helper —
|
|
// placed in its own package so it can import both core (for the legacy
|
|
// type) and errs (for the typed targets) without creating an import cycle
|
|
// with internal/errclass, which intentionally avoids depending on
|
|
// internal/core.
|
|
package errcompat
|
|
|
|
import (
|
|
"github.com/larksuite/cli/errs"
|
|
"github.com/larksuite/cli/internal/core"
|
|
)
|
|
|
|
// PromoteConfigError is the stage-2 boundary helper that will convert a
|
|
// *core.ConfigError into the matching typed errs.* error. In stage 1 it
|
|
// is a passthrough — the dispatcher continues to render *core.ConfigError
|
|
// via the legacy envelope path (cmd/root.go asExitError) so the wire
|
|
// shape stays identical to pre-PR. Per-domain typed migration in stage 2+
|
|
// will fill in the actual promotion logic alongside its corresponding
|
|
// wire-change announcement.
|
|
func PromoteConfigError(cfgErr *core.ConfigError) error {
|
|
if cfgErr == nil {
|
|
return nil
|
|
}
|
|
return cfgErr
|
|
}
|
|
|
|
// _ keeps the errs import live so stage-2 fill-in does not need to re-add it.
|
|
var _ = errs.CategoryConfig
|