oraios/serena · error · ValueError
Invalid JSON in nixd configuration file '{config_path}': {ex
Error message
Invalid JSON in nixd configuration file '{config_path}': {exc.msg} (line {exc.lineno}, column {exc.colno}) What it means
When the config_path file exists but is not valid JSON, json.load raises JSONDecodeError, which _load_nixd_settings converts into a ValueError that includes the file path, the parse message, and the line/column of the syntax error.
Source
Thrown at src/solidlsp/language_servers/nixd_ls.py:259
:return: The value of the nixd configuration section.
:raises ValueError: If ``config_path`` or its JSON document has an invalid shape.
:raises RuntimeError: If the configuration file cannot be read.
"""
config_path_value = custom_settings.get("config_path")
if config_path_value is None:
return cls._create_default_nixd_settings()
if not isinstance(config_path_value, str) or not config_path_value.strip():
raise ValueError("ls_specific_settings.nix.config_path must be a non-empty absolute path")
config_path = Path(config_path_value).expanduser()
if not config_path.is_absolute():
raise ValueError(f"ls_specific_settings.nix.config_path must be absolute: {config_path_value!r}")
try:
with config_path.open(encoding="utf-8") as config_file:
settings = json.load(config_file)
except json.JSONDecodeError as exc:
raise ValueError(
f"Invalid JSON in nixd configuration file '{config_path}': {exc.msg} (line {exc.lineno}, column {exc.colno})"
) from exc
except OSError as exc:
raise RuntimeError(f"Failed to read nixd configuration file '{config_path}': {exc}") from exc
if not isinstance(settings, dict):
raise ValueError(
f"Invalid nixd configuration file '{config_path}': expected a JSON object containing the value of the 'nixd' section"
)
return settings
@staticmethod
def _resolve_nixd_configuration_section(settings: dict[str, Any], section: object) -> Any:
"""Resolve a ``nixd`` configuration section from the effective settings."""
if section == "nixd":
return deepcopy(settings)
if not isinstance(section, str) or not section.startswith("nixd."):
return {}View on GitHub (pinned to 7fcbca7e62)
Solutions
- Fix the JSON at the reported line/column (remove trailing commas, comments, or stray characters).
- Validate the file with `python -m json.tool <config_path>` before restarting.
- Regenerate the file if truncated, or point config_path at a known-good nixd settings file.
Example fix
// before (nixd.json)
{ "nixd": { "formatting": { "command": ["nixfmt"], }, } }
// after
{ "nixd": { "formatting": { "command": ["nixfmt"] } } } Defensive patterns
Strategy: validation
Validate before calling
import json from pathlib import Path p = Path(config_path).expanduser() json.loads(p.read_text(encoding="utf-8")) # raises with line/col before server start
Try / catch
try:
server = NixdLanguageServer(...)
except ValueError as e:
if "Invalid JSON in nixd configuration file" in str(e):
restore_valid_config() # e.g. regenerate or fix the reported line/column
else:
raise Prevention
- Validate JSON with `python -m json.tool` after every manual edit.
- Never put JSONC comments or trailing commas in nixd config files.
- Keep nixd config files under version control to catch truncation/corruption.
When it happens
Trigger: The file at ls_specific_settings.nix.config_path contains a JSON syntax error (trailing comma, comments, single quotes, truncation) and the nixd language server is constructed.
Common situations: Hand-edited nixd config with a trailing comma; writing JSONC-style comments into a .json file; a crashed editor leaving a truncated file; copying YAML into a .json file.
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
- gopls_settings must be JSON-serializable (json.dumps). Use J
- ls_specific_settings.nix.config_path must be a non-empty abs
- ls_specific_settings.nix.config_path must be absolute: {conf
- Invalid nixd configuration file '{config_path}': expected a
- Dashboard is not running.
AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29).
Data as JSON: /api/errors/b9a8a4f1b6384f6a.
Report an issue: GitHub.