dgraph-io/dgraph · error

while unquoting

Error message

while unquoting: %w

What it means

ParseRDF (chunker/rdf_parser.go:133) lexes an N-Quad line and, for an itemLiteral token, unquotes the literal with strconv.Unquote to recover the raw string. If the literal is not a properly quoted/escaped Go-style string, Unquote fails and this error is returned wrapping the cause. It means an object literal in the RDF line has malformed quoting or escaping.

Solutions

  1. Fix the literal's quoting: ensure it is fully wrapped in double quotes with valid escapes (\", \\, \n, \t, \uXXXX).
  2. Escape raw newlines/tabs as \n and \t inside literals; strip smart quotes.
  3. Regenerate the export from the source tool rather than hand-editing, and validate each line with strconv.Unquote before parsing.

Example fix

// before
<0x1> <name> "line1
line2" .
// after
<0x1> <name> "line1\nline2" .
Defensive patterns

Strategy: try-catch

Validate before calling

func literalIsQuoted(line string) error {
	// extract each "..." literal and verify Go-style unquoting works
	for _, lit := range regexp.MustCompile(`"[^"]*"`).FindAllString(line, -1) {
		if _, err := strconv.Unquote(lit); err != nil {
			return fmt.Errorf("bad literal %q: %v", lit, err)
		}
	}
	return nil
}

Type guard

func isQuotedLiteral(s string) bool {
	_, err := strconv.Unquote(s)
	return err == nil
}

Try / catch

nq, err := chunker.ParseRDF(line, op)
if err != nil {
	var ui *strconv.NumError
	if strings.Contains(err.Error(), "while unquoting") {
		// repair escapes in the literal and re-parse
	}
}

Prevention

When it happens

Trigger: Calling Parse/ParseRDFs (or parseNquads) on an N-Quad whose object literal has bad quoting: unbalanced quotes, raw newlines/tabs inside the literal, or invalid escape sequences like \x or a dangling backslash.

Common situations: RDF exports generated by non-conforming tools, manual edits that broke escaping, copy-pasted values with smart quotes or real newlines inside literals, Windows-encoded files with stray characters.

Related errors


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

Appendix: source

Thrown at chunker/rdf_parser.go:133

		case itemObject:
			rnq.ObjectId = strings.TrimFunc(item.Val, isSpaceRune)

		case itemStar:
			switch {
			case rnq.Subject == "":
				rnq.Subject = x.Star
			case rnq.Predicate == "":
				rnq.Predicate = x.Star
			default:
				rnq.ObjectValue = &api.Value{Val: &api.Value_DefaultVal{DefaultVal: x.Star}}
			}

		case itemLiteral:
			var err error
			oval, err = strconv.Unquote(item.Val)
			if err != nil {
				return rnq, fmt.Errorf("while unquoting: %w", err)
			}
			seenOval = true

		case itemLanguage:
			rnq.Lang = item.Val

		case itemObjectType:
			if rnq.Predicate == x.Star || rnq.Subject == x.Star {
				return rnq, errors.New("if predicate/subject is *, value should be * as well")
			}

			val := strings.TrimFunc(item.Val, isSpaceRune)
			// TODO: Check if this condition is required.
			if val == "*" {
				return rnq, errors.New("itemObject can't be *")
			}
			// Lets find out the storage type from the type map.
			t, ok := typeMap[val]

View on GitHub (pinned to 759e242be6)