1Panel-dev/1Panel · error
unexpected end of file while scanning a string, maybe an unc
Error message
unexpected end of file while scanning a string, maybe an unclosed quote?
What it means
Panic in lexer.scanQuotedString when EOF arrives before the closing quote of a quoted token (the delimiter rune never reappeared). Escaped delimiters (\" inside "...") are handled, so this means a genuinely unterminated string literal in the nginx config.
Source
Thrown at agent/utils/nginx/parser/lexer.go:175
}
func (s *lexer) skipWhitespace() {
s.readWhile(isSpace)
}
func (s *lexer) scanComment() flag.Flag {
return s.NewToken(flag.Comment).Lit(s.readUntil(isEndOfLine))
}
func (s *lexer) scanQuotedString(delimiter rune) flag.Flag {
var buf bytes.Buffer
tok := s.NewToken(flag.QuotedString)
_, _ = buf.WriteRune(s.read())
for {
ch := s.read()
if ch == rune(flag.EOF) {
panic("unexpected end of file while scanning a string, maybe an unclosed quote?")
}
if ch == '\\' && (s.peek() == delimiter) {
buf.WriteRune(ch)
buf.WriteRune(s.read())
continue
}
_, _ = buf.WriteRune(ch)
if ch == delimiter {
break
}
}
return tok.Lit(buf.String())
}
func (s *lexer) scanKeyword() flag.Flag {View on GitHub (pinned to 5ac7c80881)
Solutions
- Locate the last edited quoted value (grep -n '"' file and check odd counts) and close the literal
- Escape embedded quotes as \" rather than leaving them bare
- Run nginx -t before reloading so syntax errors surface outside the agent's parser
Example fix
# before proxy_set_header X-Long "shortened; # after proxy_set_header X-Long "shortened";
Defensive patterns
Strategy: validation
Validate before calling
python3 - <<'PY'
import sys, re
for i, line in enumerate(open(sys.argv[1]), 1):
for q in ('"', "'"):
if len(re.findall(q, line)) % 2 == 1:
print(f'odd {q!r} count on line {i}: {line.rstrip()}')
PY <config-file> Prevention
- Keep quotes paired on a single line in nginx configs; escape \" inside values
- nginx -t before reload; it reports unterminated strings with line numbers
When it happens
Trigger: Parsing a config with a directive like proxy_set_header X-Foo "bar; or return 301 'target; — the opening " or ' is never closed before end of file.
Common situations: Hand-editing a regex or header value and dropping the closing quote; a generated config where a variable expanded to text containing a quote; copy-paste truncation.
Related errors
- unexpected end of file while scanning a string, maybe an unc
- no enough parameter for location
- unexpected token %s (%s) on line %d, column %d
- Fatal error config file: %s \n
- init db dir failed, err: %v
AI-assisted analysis of 1Panel-dev/1Panel@5ac7c80881 (2026-08-15).
Data as JSON: /api/errors/4f416f228a9ac329.
Report an issue: GitHub.