JoshuaKGoldberg / JoshuaKGoldberg/prune-github-notifications
🚀 Feature: Give a friendly CLI error when a Zod validation fails
- Dominant language
- TypeScript
- Stars
- 7
- Forks
- 0
- Avg merge
- 12m
- Merged PRs (30d)
- 35
Description
### Bug Report Checklist
- [X] I have pulled the latest `main` branch of the repository.
- [X] I have [searched for related issues](https://github.com/JoshuaKGoldberg/prune-github-notifications/issues?q=is%3Aissue) and found none that matched my issue.
### Overview
If you run `npx prune-github-notifications@0.2.1` without providing a `GH_TOKEN` environment variable or an `--auth` option, you get this lovely error:
```plaintext
$ npx prune-github-notifications@0.2.1
Failed to run prune-github-notifications: ZodError: [
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": [
"auth"
],
"message": "--auth is required if a GH_TOKEN environment variable is not specified."
}
]
at get error [as error] (file:///Users/josh/.npm/_npx/b671f4442055dc3a/node_modules/zod/lib/index.mjs:538:31)
at ZodObject.parse (file:///Users/josh/.npm/_npx/b671f4442055dc3a/node_modules/zod/lib/index.mjs:638:22)
at pruneGitHubNotificationsCLI (file:///Users/josh/.npm/_npx/b671f4442055dc3a/node_modules/prune-github-notifications/lib/cli.js:33:53)
at file:///Users/josh/.npm/_npx/b671f4442055dc3a/node_modules/prune-github-notifications/bin/index.js:6:8
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12) {
issues: [
{
code: 'invalid_type',
expected: 'string',
received: 'undefined',
path: [Array],
message: '--auth is required if a GH_TOKEN environment variable is not specified.'
}
],
addIssue: [Function (anonymous)],
addIssues: [Function (anonymous)],
errors: [
{
code: 'invalid_type',
expected: 'string',
received: 'undefined',
path: [Array],
message: '--auth is required if a GH_TOKEN environment variable is not specified.'
}
]
}
```
Lovely.
There's no need for the CLI to give such a verbose error. 1-2 lines explaining the `message`, perhaps with the `auth` path mentioned, should be enough.
### Additional Info
Ideally I'd have some nice pre-built separate package that wraps CLI parsing and formatting (even printing?) validation errors. https://github.com/causaly/zod-validation-error and https://github.com/GregBrimble/zodcli look like they're in that direction, but I haven't taken a deep dive yet.
Assigning to myself as I'd like to make a real effort here & reuse it in my other packages.
Contributor guide
Assessment
This issue has not been assessed yet.