{"record":{"id":"0e0e419529ef358f","repo":"dgraph-io/dgraph","slug":"while-parsing-namespace","errorCode":null,"errorMessage":"While parsing namespace:","messagePattern":"While parsing namespace:","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/parse.go","lineNumber":691,"sourceCode":"\t\t\t}\n\t\t\treturn &result, nil\n\n\t\tcase itemText:\n\t\t\t// For schema which does not contain the namespace information, use the default\n\t\t\t// namespace, if namespace has to be preserved. Else, use the passed namespace.\n\t\t\tns := x.RootNamespace\n\t\t\tif namespace != math.MaxUint64 {\n\t\t\t\tns = namespace\n\t\t\t}\n\t\t\tif err := parseTypeOrSchema(item, it, ns); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\tcase itemLeftSquare:\n\t\t\t// We expect a namespace.\n\t\t\tns, err := parseNamespace(it)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, errors.Wrapf(err, \"While parsing namespace:\")\n\t\t\t}\n\t\t\tif namespace != math.MaxUint64 {\n\t\t\t\t// Use the passed namespace, if we don't want to preserve the namespace.\n\t\t\t\tns = namespace\n\t\t\t}\n\t\t\t// We have already called next in parseNamespace.\n\t\t\titem := it.Item()\n\t\t\tif err := parseTypeOrSchema(item, it, ns); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\tcase itemNewLine:\n\t\t\t// pass empty line\n\n\t\tdefault:\n\t\t\treturn nil, it.Item().Errorf(\"Unexpected token: %v while parsing schema\", item)\n\t\t}\n\t}","sourceCodeStart":673,"sourceCodeEnd":709,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/schema/parse.go#L673-L709","documentation":"parse wraps any error from parseNamespace with 'While parsing namespace:'. This is an outer context message: the actual failure is one of the inner namespace errors (peek failure, type mismatch, or no schema after namespace). It indicates the schema string contains a '[' section that could not be parsed as a namespace.","triggerScenarios":"schema.Parse/ParseWithNamespace/ToDirectedEdges given schema text with malformed namespace brackets such as '[' with no number, '[x]', or '[' at EOF.","commonSituations":"Manual schema edits breaking the [0x1] header; scripts interpolating an empty namespace variable producing '[]' or '['; concatenating schema files incorrectly.","solutions":["Inspect the wrapped inner error to see the specific token problem","Fix the namespace section to the form [0x1] (number then closing bracket), or remove it if namespaces are unnecessary","If interpolating namespace values in scripts, validate the value is a non-empty number before templating","Log the full schema string at parse time to locate the offending bracket"],"exampleFix":"// before\nschema := fmt.Sprintf(\"[%s]\\nname: string .\", ns) // ns empty -> \"[]\"\n// after\nschema := fmt.Sprintf(\"[0x%x]\\nname: string .\", nsUint)","handlingStrategy":"validation","validationCode":"if strings.Contains(schemaStr, \"[\") && !regexp.MustCompile(`\\[0x[0-9a-fA-F]+\\]`).MatchString(schemaStr) {\n    return fmt.Errorf(\"malformed namespace bracket in schema\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := schema.Parse(s, 0, 1); err != nil {\n    if strings.Contains(err.Error(), \"While parsing namespace\") {\n        return fmt.Errorf(\"fix [ns] section: %w\", err)\n    }\n    return err\n}","preventionTips":["Generate the namespace header from a validated numeric value","Never interpolate raw/empty namespace strings into schema templates","Run a schema linter before ALTER calls"],"tags":["dgraph","schema-parser","parsing","namespace"],"backgroundTag":"schema-parse-invalid-namespace","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}