Significant-Gravitas/AutoGPT · warning · Error

Invalid form

Error message

Invalid form

What it means

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.

Source

Thrown at autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/EditScheduleModal/useEditScheduleModal.ts:71

  );

  function humanizeToCron(): string {
    const [hh, mm] = time.split(":");
    const minute = Number(mm || 0);
    const hour = Number(hh || 0);
    if (repeat === "weekly") {
      const dow = selectedDays.length ? selectedDays.join(",") : "*";
      return `${minute} ${hour} * * ${dow}`;
    }
    return `${minute} ${hour} * * *`;
  }

  const { mutateAsync, isPending } = useMutation({
    mutationKey: ["patchSchedule", schedule.id],
    mutationFn: async () => {
      const errorsNow = validateSchedule({ scheduleName: name, time });
      setErrors(errorsNow);
      if (Object.keys(errorsNow).length > 0) throw new Error("Invalid form");

      const cron = humanizeToCron();
      const res = await fetch(`/api/schedules/${schedule.id}`, {
        method: "PATCH",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ name, cron }),
      });
      if (!res.ok) {
        let message = "Failed to update schedule";
        try {
          const data = await res.json();
          message = data?.message || data?.detail || message;
        } catch {
          try {
            message = await res.text();
          } catch {}
        }
        throw new Error(message);

View on GitHub (pinned to 9c8bb5550f)

Solutions

  1. Fix the highlighted form fields — the form now shows exactly which inputs failed via setErrors; the throw is cosmetic for React Query flow control.
  2. If no fields appear highlighted, inspect validateSchedule for the exact rule set and compare against submitted values.
  3. 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.
Defensive patterns

Strategy: validation

Validate before calling

const errors = validateSchedule({ scheduleName: name, time });
if (Object.keys(errors).length > 0) {
  // don't call mutate() at all — disable submit instead
}

Type guard

function isInvalidFormSentinel(err: unknown): boolean {
  return err instanceof Error && err.message === "Invalid form";
}

Try / catch

onError: (error) => {
  if (isInvalidFormSentinel(error)) return; // field errors already shown via setErrors
  toast({ title: "Failed to update schedule", description: error.message, variant: "destructive" });
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Significant-Gravitas/AutoGPT@9c8bb5550f (2026-08-14). Data as JSON: /api/errors/506cd62d462402b6. Report an issue: GitHub.