fix: guard against null schedule crashing /tasks page#1567
fix: guard against null schedule crashing /tasks page#1567sweetmantech wants to merge 1 commit intomainfrom
Conversation
Some accounts have scheduled_actions with null/empty schedule values, causing the /tasks page to crash when calling .trim() or .split() on null. Added null guards in: - TaskCard.tsx: guard isRecurring() and parseCronToHuman() calls - TaskDetailsDialogContent.tsx: fallback to empty string for schedule prop - parseCronToHuman.ts: early return for falsy input - isRecurring.ts: early return for falsy input
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe pull request adds null/undefined safety checks across task scheduling components and utility functions. Guard clauses now prevent errors when task.schedule is absent, with UI components displaying "No schedule" and utility functions returning falsy defaults. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/tasks/parseCronToHuman.ts (1)
3-4: Solid defensive guard — consider tightening the type signature.The early return for falsy input prevents runtime errors and follows the fail-fast principle. However, the function signature declares
cronExpression: stringwhile the guard explicitly handlesnull/undefined. For better developer experience and self-documenting code, consider aligning the type with actual usage:💡 Optional: Explicit nullable type for clarity
-export const parseCronToHuman = (cronExpression: string): string => { +export const parseCronToHuman = (cronExpression: string | null | undefined): string => { if (!cronExpression) return "No schedule";This makes the defensive behavior explicit in the contract rather than an implementation detail.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/tasks/parseCronToHuman.ts` around lines 3 - 4, The function parseCronToHuman currently accepts cronExpression: string but guards against falsy values; change its parameter type to reflect nullable inputs (e.g., cronExpression: string | null | undefined or string | undefined) and update any related call sites/types if necessary so the contract matches the implementation; ensure the early-return "No schedule" behavior remains unchanged and run type checks to catch any callers that need adjustment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@lib/tasks/parseCronToHuman.ts`:
- Around line 3-4: The function parseCronToHuman currently accepts
cronExpression: string but guards against falsy values; change its parameter
type to reflect nullable inputs (e.g., cronExpression: string | null | undefined
or string | undefined) and update any related call sites/types if necessary so
the contract matches the implementation; ensure the early-return "No schedule"
behavior remains unchanged and run type checks to catch any callers that need
adjustment.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5dd24320-06bb-4632-a39f-ef3b76abcb0e
📒 Files selected for processing (4)
components/VercelChat/dialogs/tasks/TaskDetailsDialogContent.tsxcomponents/VercelChat/tools/tasks/TaskCard.tsxlib/tasks/isRecurring.tslib/tasks/parseCronToHuman.ts
Problem
The
/taskspage crashes for some accounts becausetask.scheduleis null/undefined at runtime, even though the DB type declares it asstring.Calling
.trim()on null inTaskCard.tsxthrows an unhandled exception that crashes the React tree.Fix
isRecurring(task.schedule)andparseCronToHuman(task.schedule.trim())"No schedule"for falsy inputfalsefor falsy inputDefensive checks at both the component and utility level so this class of bug cannot recur.
Summary by CodeRabbit