dgraph-io/dgraph · error

facet: %s: %w

Error message

facet: %s: %w

What it means

After the arity check, GetTokens resolves the tokenizer by its byte ID via GetTokenizerByID. An unknown ID means the identifier byte is not one of the registered tokenizer identifiers (IdentExact, IdentHash, IdentTerm, IdentTrigram, IdentFullText, etc.), so tokenization cannot proceed.

Source

Thrown at chunker/json_parser.go:176

func parseScalarFacets(m map[string]interface{}, prefix string) ([]*api.Facet, error) {
	// This happens at root.
	if prefix == "" {
		return nil, nil
	}

	var facetsForPred []*api.Facet
	for fname, facetVal := range m {
		if facetVal == nil {
			continue
		}
		if !strings.HasPrefix(fname, prefix) {
			continue
		}

		key := fname[len(prefix):]
		facet, err := handleBasicFacetsType(key, facetVal)
		if err != nil {
			return nil, fmt.Errorf("facet: %s: %w", fname, err)
		}
		facetsForPred = append(facetsForPred, facet)
	}

	return facetsForPred, nil
}

// This is the response for a map[string]interface{} i.e. a struct.
type mapResponse struct {
	uid       string       // uid retrieved or allocated for the node.
	namespace uint64       // namespace to which the node belongs.
	fcts      []*api.Facet // facets on the edge connecting this node to the source if any.
	rawFacets map[string]interface{}
}

func handleBasicType(k string, v interface{}, op int, nq *api.NQuad) error {
	switch v := v.(type) {
	case json.Number:

View on GitHub (pinned to 759e242be6)

Solutions

  1. Use the exported identifier constants (tok.IdentExact, tok.IdentTerm, ...) instead of literal bytes.
  2. Rebuild the index if the stored tokenizer ID came from an incompatible older version.
  3. Validate the id with tok.GetTokenizerByID(id) and handle !found gracefully before tokenizing.

Example fix

// before
const id byte = 9
tokens, err := tok.GetTokens(id, val)
// after
id := byte(tok.IdentExact)
tokens, err := tok.GetTokens(id, val)
Defensive patterns

Strategy: validation

Validate before calling

if _, ok := tok.GetTokenizerByID(id); !ok {
    return fmt.Errorf("tokenizer id %d not registered", id)
}

Try / catch

tokens, err := tok.GetTokens(id, value)
if err != nil && strings.Contains(err.Error(), "No tokenizer was found with id") {
    return nil, fmt.Errorf("tokenizer id %d unknown; rebuild index or use tok constants", id)
}

Prevention

When it happens

Trigger: Calling tok.GetTokens(id, value) with a byte id that is not a registered tokenizer ID — e.g. an id read from corrupted index metadata or a hardcoded wrong constant.

Common situations: Index/posting metadata written by a different Dgraph version using different ID assignments; corrupted schema or index files; code inventing an ID instead of using tok package constants.

Related errors


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