Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildErrorEnvelope ¶
BuildErrorEnvelope returns the full {data:null, meta, error} envelope for err. Used by json/ndjson error rendering; table mode uses BuildErrorRecord directly and renders the inner record as a KV table.
func BuildErrorRecord ¶
BuildErrorRecord returns the {code, message, retryable, ...} triple for err, suitable for embedding under the "error" key of the envelope. Resolution order:
- If err (or any error in its chain) implements ErrorPayloadBuilder, use its payload verbatim.
- Else if err is a *frameworkerrors.CLIError, derive code/message from its fields and retryable from IsRetryable().
- Fallback for plain errors: code="UNKNOWN", message=err.Error(), retryable=false.
Types ¶
type Context ¶
type Context struct {
Input *frameworkadapter.RawInput
Parsed *frameworkrouter.ParsedCommand
Values map[string]any
Result *executor.RawResult
Options *FormatOptions
}
type EnvelopeHook ¶
type EnvelopeHook struct{}
EnvelopeHook wraps the result payload in {data, meta, error} when --envelope is set. It only fires on the success path; the error-path envelope (which must appear regardless of --envelope per the design spec §"错误处理契约") is built by BuildErrorEnvelope and emitted through Processor.RenderError — see processor.go and pkg/runtime/cliapp/app.go (executeParsed → renderErrorEnvelope) for the full flow. Keeping success and error envelope logic separate means EnvelopeHook never has to reason about nil data or partially-populated state.Result.
func (EnvelopeHook) Name ¶
func (h EnvelopeHook) Name() string
type ErrorPayloadBuilder ¶
ErrorPayloadBuilder lets domain-specific error types (e.g. product-level MeegleError) plug their own {code, message, retryable, ...} shape into the unified envelope. When the implementation returns a non-nil map, its contents replace the default record built from CLIError fields; the caller MUST include at least "code", "message", and "retryable" keys so agents parsing the envelope can rely on the documented contract.
type FieldSelectorHook ¶
type FieldSelectorHook struct{}
func (FieldSelectorHook) Name ¶
func (h FieldSelectorHook) Name() string
type FormatOptions ¶
type FormatOptions struct {
Mode string
Select []string
Envelope bool
Verbose bool
// ErrorEnvelope is set by Processor.RenderError when formatting the
// pre-built error envelope `{data:null, meta, error:{code,message,retryable}}`.
// Downstream formatters must not re-wrap or peel the payload, and table
// mode renders the inner error record as a KV table rather than the full
// envelope. Not user-settable.
ErrorEnvelope bool
}
type OutputHook ¶
type Processor ¶
type Processor struct {
Hooks []OutputHook
Formatter Formatter
Writer IOWriter
Options *FormatOptions
}
func (*Processor) RenderError ¶
RenderError formats err as the unified error envelope and returns the rendered bytes for stderr. The hook chain is intentionally bypassed — hooks are designed for success data and assume a non-error payload. The formatter receives FormatOptions.ErrorEnvelope=true so downstream (e.g. CompositeFormatter) can switch table mode to render the inner error record as KV and skip wrapper-unwrapping. Returns (nil, nil) when err is nil.
Callers (usually App.Execute) should write the returned bytes to stderr and propagate the original err so the process exit code stays correct.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package encoders provides atomic byte encoders for the framework output pipeline.
|
Package encoders provides atomic byte encoders for the framework output pipeline. |
|
Package formatter provides the framework-level Formatter and IOWriter implementations.
|
Package formatter provides the framework-level Formatter and IOWriter implementations. |