Skip to content

Errors

dreamcli provides structured errors with codes, suggestions, and JSON serialization.

CLIError

ts
import {  } from '@kjanat/dreamcli';

const  = 'production';
const  = 'us';

throw new ('Deployment failed', {
  : 'DEPLOY_FAILED',
  : 1,
  : 'Check your credentials with `mycli login`',
  : { ,  },
});

Fields

FieldTypeDescription
messagestringHuman-readable error message
codestringStable machine identifier
exitCodenumberProcess exit code (default varies by type)
suggeststringActionable hint for the user
detailsunknownStructured payload for JSON output
causeError | undefinedUnderlying cause (optional)

Type Safety

ts
import {  } from '@kjanat/dreamcli';

new ('Deployment failed', {
  : 'DEPLOY_FAILED',
  exitCode: '1',
Type 'string' is not assignable to type 'number'.
});

Error Types

ts
import {
  ,
  ,
  ,
} from '@kjanat/dreamcli';
  • CLIError — base error for application-level failures
  • ParseError — argv parsing failures (unknown flags, bad syntax)
  • ValidationError — value validation failures (wrong type, missing required)

Parse and validation errors include "did you mean?" suggestions automatically.

Type Guards

ts
import {
  ,
  ,
  ,
  ,
} from '@kjanat/dreamcli';

const  = ('mycli');

try {
  await .();
} catch () {
  if (()) {
    // handle parse error
  } else if (()) {
    // handle validation error
  } else if (()) {
    // handle generic CLI error
  }
}

JSON Mode

In --json mode, errors serialize to structured JSON:

json
{
  "error": {
    "message": "Deployment failed",
    "code": "DEPLOY_FAILED",
    "suggest": "Check your credentials with `mycli login`",
    "details": { "target": "production", "region": "us" }
  }
}

What's Next?

  • Middleware — error handling in middleware chains
  • Output — output channel behavior

Released under the MIT License.