{"record":{"id":"958121d68b16a1d6","repo":"dgraph-io/dgraph","slug":"while-writing-schema-file","errorCode":null,"errorMessage":"while writing schema file","messagePattern":"while writing schema file","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dgraph/cmd/migrate/run.go","lineNumber":169,"sourceCode":"// then it dumps schema to the writer backed by schemaOutput, and data in RDF format\n// to the writer backed by dataOutput\nfunc generateSchemaAndData(dumpMeta *dumpMeta, schemaOutput string, dataOutput string) error {\n\tschemaWriter, schemaCancelFunc, err := getFileWriter(schemaOutput)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer schemaCancelFunc()\n\tdataWriter, dataCancelFunc, err := getFileWriter(dataOutput)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer dataCancelFunc()\n\n\tdumpMeta.dataWriter = dataWriter\n\tdumpMeta.schemaWriter = schemaWriter\n\n\tif err := dumpMeta.dumpSchema(); err != nil {\n\t\treturn errors.Wrapf(err, \"while writing schema file\")\n\t}\n\tif err := dumpMeta.dumpTables(); err != nil {\n\t\treturn errors.Wrapf(err, \"while writing data file\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":151,"sourceCodeEnd":176,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dgraph/cmd/migrate/run.go#L151-L176","documentation":"In generateSchemaAndData, the error returned by dumpSchema is re-wrapped with \"while writing schema file\", adding call-site context (which output file phase failed) on top of dumpSchema's own \"while writing schema\" wrapper. The root cause remains the underlying write error.","triggerScenarios":"Any failure inside dumpSchema (schemaWriter.WriteString or Flush error) surfaces with this message: unwritable schema output path, disk full, or file handle issues during dgraph migrate.","commonSituations":"Schema output path is a directory or read-only file; disk quota exceeded; running as a user without write permission on the output directory.","solutions":["Print the error with %+v to see the full wrap chain and root cause.","Check disk space and write permissions for the schema output path.","Confirm the schema path is a writable regular file, then rerun migrate."],"exampleFix":"// before\ndgraph migrate --schema /etc/dgraph/schema.txt  # read-only dir\n// after\nmkdir -p ~/migrate-out && dgraph migrate --schema ~/migrate-out/schema.txt","handlingStrategy":"try-catch","validationCode":"if err := canWrite(filepath.Dir(schemaPath)); err != nil {\n\treturn fmt.Errorf(\"cannot write schema to %s: %w\", schemaPath, err)\n}","typeGuard":"func isSchemaWriteErr(err error) bool {\n\treturn strings.Contains(err.Error(), \"while writing schema file\")\n}","tryCatchPattern":"if err := migrate.Run(); err != nil {\n\tif isSchemaWriteErr(err) {\n\t\tlog.Printf(\"root cause: %+v\", errors.Cause(err))\n\t}\n}","preventionTips":["Run migrate as a user with write access to the output directory","Check disk quota/space before starting","Use pkg/errors %+v to read the full wrap chain"],"tags":["io","migration","file-write"],"backgroundTag":"disk-full-write-failure","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}