siyuan-note/siyuan · warning
variable %q contains NUL
Error message
variable %q contains NUL
What it means
Validation error from validateMCPServerEnvironment: an explicit Env value contains a NUL byte (\x00). NUL cannot appear in a C environ entry and would silently truncate the value when passed to the child. The offending variable name is quoted via %q so you can locate it.
Source
Thrown at kernel/mcp/client/mcp.go:562
func validateMCPServerEnvironment(server conf.MCPServer, goos string) error {
inherited := map[string]bool{}
for _, name := range server.InheritEnv {
if err := validateEnvironmentName(name); err != nil {
return err
}
key := environmentKey(name, goos)
if inherited[key] {
return fmt.Errorf("duplicate inherited variable %q", name)
}
inherited[key] = true
}
explicit := map[string]bool{}
for name, value := range server.Env {
if err := validateEnvironmentName(name); err != nil {
return err
}
if strings.ContainsRune(value, '\x00') {
return fmt.Errorf("variable %q contains NUL", name)
}
key := environmentKey(name, goos)
if explicit[key] {
return fmt.Errorf("duplicate variable %q", name)
}
explicit[key] = true
}
return nil
}
// ValidateMCPServerEnvironment 校验当前平台上的 stdio 环境变量配置。
func ValidateMCPServerEnvironment(server conf.MCPServer) error {
return validateMCPServerEnvironment(server, runtime.GOOS)
}
func defaultMCPEnvironmentNames(goos string) []string {
if goos == "windows" {
return []string{"APPDATA", "HOMEDRIVE", "HOMEPATH", "LOCALAPPDATA", "PATH", "PATHEXT",View on GitHub (pinned to 251596fc0d)
Solutions
- Locate the variable named in the error message and rewrite its value without NUL bytes.
- If the value comes from model.Conf.Secrets / Variables via ResolveSecretsVars, inspect the source of that secret for corruption.
- Strip NUL bytes programmatically before writing the config: strings.ReplaceAll(value, "\x00", "").
Example fix
// before (value contains a stray NUL)
"env": {"TOKEN": "abc\u0000def"}
// after
"env": {"TOKEN": "abcdef"} Defensive patterns
Strategy: validation
Validate before calling
import "strings"
func sanitizeEnvValue(v string) string {
return strings.ReplaceAll(v, "\x00", "")
} Prevention
- Audit secret sources for embedded NUL bytes.
- Sanitize values read from external stores before assigning to Env.
When it happens
Trigger: Iterating server.Env, validateMCPServerEnvironment runs strings.ContainsRune(value, '\x00') on each value; if a value contains a NUL byte, this error is returned for the corresponding name.
Common situations: Value was read from a binary file or pasted from a terminal that embedded a control character; secret material loaded from a corrupted credential store; mistaken use of a byte slice containing a trailing NUL (e.g. C-go interop residue).
Related errors
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/2afc1a34bb3a7558.
Report an issue: GitHub.