{"record":{"id":"506cd62d462402b6","repo":"Significant-Gravitas/AutoGPT","slug":"invalid-form","errorCode":null,"errorMessage":"Invalid form","messagePattern":"Invalid form","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/EditScheduleModal/useEditScheduleModal.ts","lineNumber":71,"sourceCode":"  );\n\n  function humanizeToCron(): string {\n    const [hh, mm] = time.split(\":\");\n    const minute = Number(mm || 0);\n    const hour = Number(hh || 0);\n    if (repeat === \"weekly\") {\n      const dow = selectedDays.length ? selectedDays.join(\",\") : \"*\";\n      return `${minute} ${hour} * * ${dow}`;\n    }\n    return `${minute} ${hour} * * *`;\n  }\n\n  const { mutateAsync, isPending } = useMutation({\n    mutationKey: [\"patchSchedule\", schedule.id],\n    mutationFn: async () => {\n      const errorsNow = validateSchedule({ scheduleName: name, time });\n      setErrors(errorsNow);\n      if (Object.keys(errorsNow).length > 0) throw new Error(\"Invalid form\");\n\n      const cron = humanizeToCron();\n      const res = await fetch(`/api/schedules/${schedule.id}`, {\n        method: \"PATCH\",\n        headers: { \"Content-Type\": \"application/json\" },\n        body: JSON.stringify({ name, cron }),\n      });\n      if (!res.ok) {\n        let message = \"Failed to update schedule\";\n        try {\n          const data = await res.json();\n          message = data?.message || data?.detail || message;\n        } catch {\n          try {\n            message = await res.text();\n          } catch {}\n        }\n        throw new Error(message);","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/EditScheduleModal/useEditScheduleModal.ts#L53-L89","documentation":"Thrown by the schedule-edit modal's useMutation when validateSchedule({scheduleName, time}) produced at least one field error (the modal sets those errors on the form via setErrors before throwing). It aborts the PATCH /api/schedules/{id} call before any network activity. 'Invalid form' is the sentinel used to distinguish client-side validation failure from server failure in onError handling.","triggerScenarios":"Submitting the edit-schedule modal with an empty schedule name, a time that fails the time format/range validation, or any other rule in validateSchedule — the mutationFn checks errorsNow immediately and throws before fetch.","commonSituations":"User clears the name field and hits Save; time input left blank or in an unparseable format; a stale form state where the time default didn't populate for an existing schedule.","solutions":["Fix the highlighted form fields — the form now shows exactly which inputs failed via setErrors; the throw is cosmetic for React Query flow control.","If no fields appear highlighted, inspect validateSchedule for the exact rule set and compare against submitted values.","Developers: consider throwing the errors object or using zod like sibling forms so onError can differentiate; the string 'Invalid form' is only a control-flow sentinel."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const errors = validateSchedule({ scheduleName: name, time });\nif (Object.keys(errors).length > 0) {\n  // don't call mutate() at all — disable submit instead\n}","typeGuard":"function isInvalidFormSentinel(err: unknown): boolean {\n  return err instanceof Error && err.message === \"Invalid form\";\n}","tryCatchPattern":"onError: (error) => {\n  if (isInvalidFormSentinel(error)) return; // field errors already shown via setErrors\n  toast({ title: \"Failed to update schedule\", description: error.message, variant: \"destructive\" });\n}","preventionTips":["Gate the submit button on form validity so mutationFn never runs with errors.","Use the sentinel string check in onError to skip duplicate toasts when field errors are already displayed.","Prefer zod schemas (as sibling forms do) over imperative validateSchedule for consistent error shapes."],"tags":["validation","schedule","react-query","frontend","form"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}