{"record":{"id":"cd3c8d39ed028641","repo":"hasura/graphql-engine","slug":"error-encoding-migration-status-as-json-w","errorCode":null,"errorMessage":"error encoding migration status as json: %w","messagePattern":"error encoding migration status as json: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/pkg/migrate/status.go","lineNumber":86,"sourceCode":"\t}\n\n\treturn migrateStatus, nil\n}\n\nfunc (p *projectMigrationsStatus) StatusJSON(\n\topts ...ProjectMigrationStatusOption,\n) (io.Reader, error) {\n\tvar op errors.Op = \"migrate.projectMigrationsStatus.StatusJSON\"\n\n\td, err := p.Status(opts...)\n\tb := new(bytes.Buffer)\n\n\tif err != nil {\n\t\treturn nil, errors.E(op, err)\n\t}\n\n\tif err := json.NewEncoder(b).Encode(d); err != nil {\n\t\treturn nil, errors.E(op, fmt.Errorf(\"error encoding migration status as json: %w\", err))\n\t}\n\n\treturn b, nil\n}\n\ntype ProjectMigrationStatusOption func(applier *projectMigrationsStatus)\n\nfunc newProjectMigrationsStatus(ec *cli.ExecutionContext) *projectMigrationsStatus {\n\tp := &projectMigrationsStatus{ec: ec}\n\n\treturn p\n}\n\nfunc StatusAllDatabases() ProjectMigrationStatusOption {\n\treturn func(p *projectMigrationsStatus) {\n\t\tp.allDatabases = true\n\t}\n}","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/pkg/migrate/status.go#L68-L104","documentation":"StatusJSON failed while streaming a json.Encoding of the migration status value into a buffer. This is a stdlib encoding/json failure, which for an in-memory bytes.Buffer-backed encoder is only produced by the value's MarshalJSON method returning an error. The library wraps it with errors.E under the op 'StatusJSON' (or similar) so it carries the operation context.","triggerScenarios":"Calling StatusJSON (or any caller of json.NewEncoder(b).Encode(d)) where the migration status value d implements json.Marshaler and its MarshalJSON returns an error — e.g. a channel, function, or complex number field, or a nested type whose custom MarshalJSON fails.","commonSituations":"A new field of unsupported type (chan, func, complex, NaN/Inf float with certain encoders) added to the status struct; a custom MarshalJSON on a status sub-type that errors on unexpected state; rarely, API changes that altered the status payload shape between versions.","solutions":["Inspect the wrapped error (%w) — it names the exact type/field json could not marshal.","Check any custom MarshalJSON implementations on the status struct and its nested types; ensure they never return errors for reachable states.","Remove or replace unsupported field types (channels, functions, complex numbers) in the status payload; run go vet which flags json-incompatible types.","If the error appears after a version upgrade, diff the status struct definition between releases."],"exampleFix":"// before\ntype projectStatus struct {\n\tProgress chan int `json:\"progress\"` // unsupported by encoding/json\n}\n\n// after\ntype projectStatus struct {\n\tProgress int `json:\"progress\"`\n}","handlingStrategy":"validation","validationCode":"// Verify the status value is JSON-marshalable before encoding\nif _, err := json.Marshal(d); err != nil {\n    return nil, fmt.Errorf(\"status not serializable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if b, err := status.StatusJSON(...); err != nil && strings.Contains(err.Error(), \"error encoding migration status\") {\n    // fall back to a minimal, always-marshalable status payload\n}","preventionTips":["Avoid chan/func/complex fields in types passed to StatusJSON","Keep custom MarshalJSON implementations total (never error on reachable states)","Add a unit test that json.Marshals every status variant"],"tags":["json","serialization","migration","go"],"backgroundTag":"json-marshaling-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}