dgraph-io/dgraph · error

Unexpected end of IRI

Error message

Unexpected end of IRI

What it means

The lexer's IRIRef parses `<...>` IRI references (as in N-Quads/Turtle). It reads characters until it expects the closing `>`; if input ends (EOF) before the closing bracket, the IRI is unterminated and this error is returned.

Source

Thrown at lex/iri.go:19

/*
 * SPDX-FileCopyrightText: © 2017-2026 Istari Digital, Inc.
 * SPDX-License-Identifier: Apache-2.0
 */

package lex

import (
	"github.com/pkg/errors"
)

// IRIRef emits an IRIREF or returns an error if the input is invalid.
func IRIRef(l *Lexer, styp ItemType) error {
	l.Ignore() // ignore '<'
	l.AcceptRunRec(isIRIRefChar)
	l.Emit(styp) // will emit without '<' and '>'
	r := l.Next()
	if r == EOF {
		return errors.New("Unexpected end of IRI")
	}
	if r != '>' {
		return errors.Errorf("Unexpected character %q while parsing IRI", r)
	}
	l.Ignore() // ignore '>'
	return nil
}

// isIRIRefChar returns whether the rune is a character allowed in an IRIRef.
// IRIREF ::= '<' ([^#x00-#x20<>"{}|^`\] | UCHAR)* '>'
func isIRIRefChar(r rune, l *Lexer) bool {
	if r <= 32 { // no chars b/w 0x00 to 0x20 inclusive
		return false
	}
	switch r {
	case '<', '>', '"', '{', '}', '|', '^', '`':
		return false
	case '\\':

View on GitHub (pinned to 759e242be6)

Solutions

  1. Fix the input so the IRI is closed with a `>`
  2. Validate/sanitize the RDF document before lexing
  3. Check for truncation at the source (upload, network, file write)
  4. Escape or reject records containing bare `<` that isn't an IRI start

Example fix

// before
<http://example.com/s> <http://example.com/p "value" .
// after
<http://example.com/s> <http://example.com/p> "value" .
Defensive patterns

Strategy: validation

Validate before calling

if !strings.Contains(line, ">") && strings.Contains(line, "<") {
  return errors.New("unterminated IRI in input")
}

Try / catch

if err := lex.IRIRef(l, item); err != nil {
  if err.Error() == "Unexpected end of IRI" {
    return fmt.Errorf("truncated input at offset %d: %w", l.Pos(), err)
  }
  return err
}

Prevention

When it happens

Trigger: lexing an RDF/N-Quads document containing `<http://example.com/x` with no closing `>`, e.g. truncated input or a line/record cut off mid-IRI.

Common situations: Truncated file uploads, network cuts mid-stream, log records missing the terminator, or hand-edited RDF files with unbalanced angle brackets.

Related errors


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