{"record":{"id":"42ddb3551e000326","repo":"chenhg5/cc-connect","slug":"failed-to-update-field-q-may-be-read-only-or-inv","errorCode":null,"errorMessage":"failed to update field %q (may be read-only or invalid type)","messagePattern":"failed to update field %q \\(may be read-only or invalid type\\)","errorType":"exception","errorClass":null,"httpStatus":400,"severity":"error","filePath":"core/cron.go","lineNumber":598,"sourceCode":"\t\t}\n\t}\n\n\t// Check if reschedule is needed\n\tneedsReschedule := field == \"cron_expr\" || field == \"enabled\"\n\n\tif needsReschedule {\n\t\t// Remove current schedule\n\t\tcs.mu.Lock()\n\t\tif entryID, ok := cs.entries[id]; ok {\n\t\t\tcs.cron.Remove(entryID)\n\t\t\tdelete(cs.entries, id)\n\t\t}\n\t\tcs.mu.Unlock()\n\t}\n\n\t// Update the field\n\tif !cs.store.Update(id, field, value) {\n\t\treturn fmt.Errorf(\"failed to update field %q (may be read-only or invalid type)\", field)\n\t}\n\n\t// Reschedule if needed\n\tif needsReschedule {\n\t\tupdatedJob := cs.store.Get(id)\n\t\tif updatedJob != nil && updatedJob.Enabled {\n\t\t\tif err := cs.scheduleJob(updatedJob); err != nil {\n\t\t\t\treturn fmt.Errorf(\"reschedule failed: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (cs *CronScheduler) Store() *CronStore {\n\treturn cs.store\n}","sourceCodeStart":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/cron.go#L580-L616","documentation":"UpdateJob applies the field change through cs.store.Update, which returns false when the field name is unknown, read-only, or the value has the wrong type for the field. The scheduler surfaces this as a wrapped error naming the offending field so callers know the persisted job was not modified.","triggerScenarios":"Calling UpdateJob(id, field, value) with a field name that does not exist on the job struct (typo like \"cronExpr\" instead of \"cron_expr\"), a read-only field (e.g. \"id\"), or a value whose type mismatches the field's stored type for non-validated fields.","commonSituations":"A command handler maps user-supplied flag names directly to field names; a config or plugin passes an outdated field name after a schema rename.","solutions":["Check the field name spelling against the supported set (e.g. \"cron_expr\", \"enabled\", \"prompt\")","Ensure the value type matches the field (string for cron_expr/prompt, bool for enabled)","Inspect store.Update to confirm the field is writable before calling","Log the returned error with job id and field for diagnosis"],"exampleFix":"// before\ncs.UpdateJob(id, \"cronExpr\", expr) // wrong field name\n// after\ncs.UpdateJob(id, \"cron_expr\", expr)","handlingStrategy":"validation","validationCode":"var validFields = map[string]bool{\"cron_expr\": true, \"enabled\": true, \"prompt\": true}\nif !validFields[field] { return fmt.Errorf(\"unsupported field %q\", field) }","typeGuard":null,"tryCatchPattern":"if err := cs.UpdateJob(id, field, val); err != nil {\n    if strings.Contains(err.Error(), \"failed to update field\") {\n        slog.Warn(\"cron edit rejected\", \"field\", field, \"err\", err)\n    }\n}","preventionTips":["Keep a single canonical list of editable field names shared by handler and store","Validate user-supplied flag names against that list before calling UpdateJob"],"tags":["go","cron","persistence"],"backgroundTag":"invalid-argument-value","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}