| name | oclif-json-and-errors |
| description | Design stable oclif command output contracts with clean --json stdout, stderr diagnostics, and structured error codes. Use when adding or refactoring command output, exit behavior, or automation-facing error handling. |
Oclif JSON and Errors
Use this skill when changing command UX or output contracts in this plugin.
When to use
- Adding a new command under
src/commands/.
- Changing
--json output shape.
- Handling partial failures where automation still needs machine-readable details.
- Standardizing exit codes and error messages.
Core rules
- Keep
--json output machine-safe.
- Keep human status logs out of JSON payloads.
- Prefer stable error codes for scriptability.
- Use one predictable schema per command mode.
Recommended pattern
- Build a typed response object first.
- Print JSON exactly once in
--json mode.
- Emit human-friendly logs only in non-JSON mode.
- On failure, include actionable context and a stable
code in this.error().
Repo guidance
- Keep JSON payloads shaped like current command contracts in
src/commands/docs/.
- For all-failed batch operations, still emit error details before non-zero exit.
- Continue using reusable helpers for consistency:
:
src/lib/errorUtils.ts
: src/lib/fileOutput.ts
Checklist
References