Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/cliffy/examples/command/validation_error_handling.ts

Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
Extremely Popular
Go to Latest
File
import { Command, ValidationError } from "../../command/mod.ts";
const cmd = new Command() .throwErrors() // <-- throw also validation errors. .option("-p, --pizza-type <type>", "Flavour of pizza.") .action(() => { throw new Error("Some error happened."); });
try { cmd.parse();} catch (error) { if (error instanceof ValidationError) { cmd.help(); console.error("[CUSTOM_VALIDATION_ERROR]", error.message); } else { console.error("[CUSTOM_ERROR]", error); } Deno.exit(1);}