dgraph-io/dgraph · error
incorrect format for specifying Dgraph secret found for comm
Error message
incorrect format for specifying Dgraph secret found for comment: `%s`, it should be `# Dgraph.Secret key value`
What it means
parseMetaInfo reads `# Dgraph.Secret key value` comments from the GraphQL schema file. This error is thrown when a Dgraph.Secret comment line has fewer than 4 whitespace-separated fields (i.e. missing the key and/or value after `# Dgraph.Secret`), so the secret cannot be parsed.
Source
Thrown at graphql/schema/schemagen.go:243
}
var allowedOrigin string
if err = json.Unmarshal([]byte(parts[2]), &allowedOrigin); err != nil {
return nil, errors.Errorf("incorrect format for specifying Dgraph.Allow-Origin"+
" found for comment: `%s`, it should be `# Dgraph."+
"Allow-Origin \"http://example.com\"`", text)
}
schMetaInfo.allowedCorsOrigins[allowedOrigin] = true
continue
}
if !strings.HasPrefix(header, "Dgraph.Secret") {
continue
}
parts := strings.Fields(text)
const doubleQuotesCode = 34
if len(parts) < 4 {
return nil, errors.Errorf("incorrect format for specifying Dgraph secret found for "+
"comment: `%s`, it should be `# Dgraph.Secret key value`", text)
}
val := strings.Join(parts[3:], " ")
if strings.Count(val, `"`) != 2 || val[0] != doubleQuotesCode || val[len(val)-1] != doubleQuotesCode {
return nil, errors.Errorf("incorrect format for specifying Dgraph secret found for "+
"comment: `%s`, it should be `# Dgraph.Secret key value`", text)
}
val = strings.Trim(val, `"`)
key := strings.Trim(parts[2], `"`)
// lets obfuscate the value of the secrets from here on.
schMetaInfo.secrets[key] = x.Sensitive(val)
}
}
if err = scanner.Err(); err != nil {
return nil, errors.Wrapf(err, "while trying to parse secrets from schema file")
}View on GitHub (pinned to 759e242be6)
Solutions
- Add both a key and a value to the comment: `# Dgraph.Secret myKey "myValue"`
- Verify the comment starts with exactly `# Dgraph.Secret` followed by key then value
- Quote the value in double quotes if it contains spaces
Example fix
// before # Dgraph.Secret apiKey // after # Dgraph.Secret apiKey "my-secret-value"
Defensive patterns
Strategy: validation
Validate before calling
func validSecretComment(line string) bool {
parts := strings.Fields(line)
return len(parts) >= 4 && parts[1] == "Dgraph.Secret"
}
// validate each schema line before passing the schema to NewHandler Prevention
- Lint schema comments so every `# Dgraph.Secret` line has key and quoted value
- Use a schema template with placeholders instead of editing comments by hand
- Run schema creation in CI to catch malformed secret lines before deploy
When it happens
Trigger: Calling NewHandler with a schema containing a comment like `# Dgraph.Secret` or `# Dgraph.Secret apiKey` with no value — strings.Fields(text) yields fewer than 4 tokens.
Common situations: Hand-edited schema files where the secret value was deleted or never filled in; copy-paste of the directive comment without the actual key/value; templating that rendered an empty secret.
Related errors
- encountered an XID %s with %s that isn'tallowed as Xid
- Unable to find the type %s on the remote schema
- Not resolving subscription because schema doesn't have any f
- while parsing GraphQL schema
- while validating GraphQL schema
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/31ef06ac8650e1ae.
Report an issue: GitHub.