{"record":{"id":"7ab713abd32ca898","repo":"dgraph-io/dgraph","slug":"while-unquoting-w","errorCode":null,"errorMessage":"while unquoting: %w","messagePattern":"while unquoting: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"chunker/rdf_parser.go","lineNumber":133,"sourceCode":"\n\t\tcase itemObject:\n\t\t\trnq.ObjectId = strings.TrimFunc(item.Val, isSpaceRune)\n\n\t\tcase itemStar:\n\t\t\tswitch {\n\t\t\tcase rnq.Subject == \"\":\n\t\t\t\trnq.Subject = x.Star\n\t\t\tcase rnq.Predicate == \"\":\n\t\t\t\trnq.Predicate = x.Star\n\t\t\tdefault:\n\t\t\t\trnq.ObjectValue = &api.Value{Val: &api.Value_DefaultVal{DefaultVal: x.Star}}\n\t\t\t}\n\n\t\tcase itemLiteral:\n\t\t\tvar err error\n\t\t\toval, err = strconv.Unquote(item.Val)\n\t\t\tif err != nil {\n\t\t\t\treturn rnq, fmt.Errorf(\"while unquoting: %w\", err)\n\t\t\t}\n\t\t\tseenOval = true\n\n\t\tcase itemLanguage:\n\t\t\trnq.Lang = item.Val\n\n\t\tcase itemObjectType:\n\t\t\tif rnq.Predicate == x.Star || rnq.Subject == x.Star {\n\t\t\t\treturn rnq, errors.New(\"if predicate/subject is *, value should be * as well\")\n\t\t\t}\n\n\t\t\tval := strings.TrimFunc(item.Val, isSpaceRune)\n\t\t\t// TODO: Check if this condition is required.\n\t\t\tif val == \"*\" {\n\t\t\t\treturn rnq, errors.New(\"itemObject can't be *\")\n\t\t\t}\n\t\t\t// Lets find out the storage type from the type map.\n\t\t\tt, ok := typeMap[val]","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/chunker/rdf_parser.go#L115-L151","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix the literal's quoting: ensure it is fully wrapped in double quotes with valid escapes (\\\", \\\\, \\n, \\t, \\uXXXX).","Escape raw newlines/tabs as \\n and \\t inside literals; strip smart quotes.","Regenerate the export from the source tool rather than hand-editing, and validate each line with strconv.Unquote before parsing."],"exampleFix":"// before\n<0x1> <name> \"line1\nline2\" .\n// after\n<0x1> <name> \"line1\\nline2\" .","handlingStrategy":"try-catch","validationCode":"func literalIsQuoted(line string) error {\n\t// extract each \"...\" literal and verify Go-style unquoting works\n\tfor _, lit := range regexp.MustCompile(`\"[^\"]*\"`).FindAllString(line, -1) {\n\t\tif _, err := strconv.Unquote(lit); err != nil {\n\t\t\treturn fmt.Errorf(\"bad literal %q: %v\", lit, err)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":"func isQuotedLiteral(s string) bool {\n\t_, err := strconv.Unquote(s)\n\treturn err == nil\n}","tryCatchPattern":"nq, err := chunker.ParseRDF(line, op)\nif err != nil {\n\tvar ui *strconv.NumError\n\tif strings.Contains(err.Error(), \"while unquoting\") {\n\t\t// repair escapes in the literal and re-parse\n\t}\n}","preventionTips":["Escape newlines/tabs/quotes in literals when generating RDF","Never hand-edit exported .rdf files; regenerate instead","Strip non-ASCII smart quotes from source data","Validate each line with strconv.Unquote before batch import"],"tags":["rdf-parser","escaping","syntax","dgraph"],"backgroundTag":"malformed-rdf-literal","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}