dgraph-io/dgraph · error

Typed oes not match the expected

Error message

Typed oes not match the expected

What it means

After peeking 2 tokens, parseNamespace requires the first to be an itemNumber and the second a closing ']'. Anything else (e.g. a name token, EOF inside brackets) yields 'Typed oes not match the expected' (typo for 'Type does not match the expected'). It means the syntax after '[' is not a numeric namespace.

Source

Thrown at schema/parse.go:587

	}

	if it.Item().Typ != itemNewLine {
		return nil, it.Item().Errorf("Expected new line after field declaration. Got %v",
			it.Item().Val)
	}

	glog.Warningf("Type declaration for type %s includes deprecated information about field type "+
		"for field %s which will be ignored.", typeName, x.ParseAttr(field.Predicate))
	return field, nil
}

func parseNamespace(it *lex.ItemIterator) (uint64, error) {
	nextItems, err := it.Peek(2)
	if err != nil {
		return 0, errors.Errorf("Unable to peek: %v", err)
	}
	if nextItems[0].Typ != itemNumber || nextItems[1].Typ != itemRightSquare {
		return 0, errors.Errorf("Typed oes not match the expected")
	}
	ns, err := strconv.ParseUint(nextItems[0].Val, 0, 64)
	if err != nil {
		return 0, err
	}
	it.Next()
	it.Next()
	// We have parsed the namespace. Now move to the next item.
	if !it.Next() {
		return 0, errors.Errorf("No schema found after namespace. Got: %v", nextItems[0])
	}
	return ns, nil
}

// ParsedSchema represents the parsed schema and type updates.
type ParsedSchema struct {
	Preds []*pb.SchemaUpdate
	Types []*pb.TypeUpdate

View on GitHub (pinned to 759e242be6)

Solutions

  1. Use the correct namespace syntax: [0x1] (a hex/decimal number followed by ']')
  2. Remove the '[' section entirely if namespaces are not used
  3. Fix the typo'd/malformed token inside the brackets and re-run Parse
  4. Upgrade Dgraph: the error message itself is malformed text and later versions clarify it

Example fix

// before
schema := "[name]\nname: string ."  // brackets contain a name, not a number
// after
schema := "[0x1]\nname: string ."
Defensive patterns

Strategy: validation

Validate before calling

re := regexp.MustCompile(`^\[0x[0-9a-fA-F]+\]$`)
for _, m := range namespaceHeaders(schemaStr) {
    if !re.MatchString(m) {
        return fmt.Errorf("bad namespace header: %s", m)
    }
}

Try / catch

if _, err := schema.Parse(s, 0, 1); err != nil {
    if strings.Contains(err.Error(), "does not match") || strings.Contains(err.Error(), "oes not match") {
        return fmt.Errorf("invalid namespace syntax in schema: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Schema text containing '[abc]' or '[ ]' or '[' followed by a predicate name instead of a namespace number, passed to schema.Parse/ParseWithNamespace/ToDirectedEdges.

Common situations: Hand-written schema where the author confused namespace syntax with array syntax; copying a GraphQL or JSON schema into DQL schema; missing namespace number inside the brackets.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/a825260573fdcdd7. Report an issue: GitHub.