nats-io/nats-server · error
Parse error on line %d: '%s'
Error message
Parse error on line %d: '%s'
What it means
processItem receives items from the lexer and, when the item type is itemError (lexical failure), converts it into "Parse error on line %d: '%s'". The library surfaces lexer-level problems — unterminated strings, illegal characters, bad tokens — at a precise line number.
Source
Thrown at conf/parse.go:283
}
li := len(p.ikeys) - 1
last := p.ikeys[li]
p.ikeys = p.ikeys[0:li]
return last
}
func (p *parser) processItem(it item, fp string) error {
setValue := func(it item, v any) {
if p.pedantic {
p.setValue(&token{it, v, false, fp})
} else {
p.setValue(v)
}
}
switch it.typ {
case itemError:
return fmt.Errorf("Parse error on line %d: '%s'", it.line, it.val)
case itemKey:
// Keep track of the keys as items and strings,
// we do this in order to be able to still support
// includes without many breaking changes.
p.pushKey(it.val)
if p.pedantic {
p.pushItemKey(it)
}
case itemMapStart:
newCtx := make(map[string]any)
p.pushContext(newCtx)
case itemMapEnd:
setValue(it, p.popContext())
case itemString:
// FIXME(dlc) sanitize string?
setValue(it, it.val)
case itemInteger:View on GitHub (pinned to 3a66a489d2)
Solutions
- Go to the reported line and fix the quoted token — close the quote or escape inner quotes
- Wrap problematic values (passwords, URLs with special chars) in single or double quotes properly
- Replace illegal characters or remove BOM/encoding artifacts
- Validate with `nats-server -t -c file.conf` after editing
Example fix
// before
authorization {
password: "p@ss'word
}
// after
authorization {
password: "p@ss'word"
} Defensive patterns
Strategy: try-catch
Try / catch
cfg, err := conf.ParseFile(fp)
if err != nil {
var line int
if n, _ := fmt.Sscanf(err.Error(), "Parse error on line %d", &line); n == 1 {
log.Fatalf("lexer failure in %s at line %d: inspect quotes/characters there", fp, line)
}
return err
} Prevention
- Quote all values containing special characters or spaces
- Never paste secrets with unbalanced quotes into configs
- Use nats-server -t as a pre-deploy syntax gate
- Normalize file encoding (UTF-8, no BOM) before parsing
When it happens
Trigger: A config file contains a token the lexer cannot handle, e.g. an unterminated quoted string, an invalid escape, or an unexpected character; processItem is invoked from parse for every token.
Common situations: Secrets pasted with a trailing unclosed quote; special characters (backticks, unescaped quotes) in passwords; variables expanded with characters the lexer rejects; Windows line-ending or encoding oddities.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- config is invalid (%s:%d:%d)
- unable to plug TLS verify connection, config is nil
- OCSP peer verification for client connections requires TLS v
- unable to register client OCSP verification
- no hostport specified
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/8cd0e9d5816f179f.
Report an issue: GitHub.