Skip to content

Commit ce8585c

Browse files
schpetbotschpet
andauthored
fix: move date validation inside try-catch in project update (#165)
Validation errors thrown before the `try` block in `project update` were bypassing `handleError`, resulting in raw stack traces instead of clean `✗` error messages. Moves the no-options check, `--start-date` format check, and `--target-date` format check inside the `try` block so they display consistently with other error messages. Found during manual QA of #148. Co-authored-by: Peter Schilling <code@schpet.com>
1 parent 69e59ee commit ce8585c

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

src/commands/project/project-update.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,33 @@ export const updateCommand = new Command()
8383
},
8484
projectId,
8585
) => {
86-
if (
87-
!name && description == null && !status && !lead &&
88-
!startDate && !targetDate && (!teams || teams.length === 0)
89-
) {
90-
throw new ValidationError(
91-
"At least one update option must be provided",
92-
{
93-
suggestion:
94-
"Use --name, --description, --status, --lead, --start-date, --target-date, or --team",
95-
},
96-
)
97-
}
98-
99-
if (startDate && !/^\d{4}-\d{2}-\d{2}$/.test(startDate)) {
100-
throw new ValidationError("Start date must be in YYYY-MM-DD format")
101-
}
102-
103-
if (targetDate && !/^\d{4}-\d{2}-\d{2}$/.test(targetDate)) {
104-
throw new ValidationError("Target date must be in YYYY-MM-DD format")
105-
}
106-
10786
const { Spinner } = await import("@std/cli/unstable-spinner")
10887
const showSpinner = shouldShowSpinner()
10988
const spinner = showSpinner ? new Spinner() : null
110-
spinner?.start()
11189

11290
try {
91+
if (
92+
!name && description == null && !status && !lead &&
93+
!startDate && !targetDate && (!teams || teams.length === 0)
94+
) {
95+
throw new ValidationError(
96+
"At least one update option must be provided",
97+
{
98+
suggestion:
99+
"Use --name, --description, --status, --lead, --start-date, --target-date, or --team",
100+
},
101+
)
102+
}
103+
104+
if (startDate && !/^\d{4}-\d{2}-\d{2}$/.test(startDate)) {
105+
throw new ValidationError("Start date must be in YYYY-MM-DD format")
106+
}
107+
108+
if (targetDate && !/^\d{4}-\d{2}-\d{2}$/.test(targetDate)) {
109+
throw new ValidationError("Target date must be in YYYY-MM-DD format")
110+
}
111+
112+
spinner?.start()
113113
const client = getGraphQLClient()
114114
const resolvedId = await resolveProjectId(projectId)
115115

0 commit comments

Comments
 (0)