{"record":{"id":"cf4678934104ba95","repo":"oraios/serena","slug":"invalid-nixd-configuration-file-config-path-e","errorCode":null,"errorMessage":"Invalid nixd configuration file '{config_path}': expected a JSON object containing the value of the 'nixd' section","messagePattern":"Invalid nixd configuration file '(.+?)': expected a JSON object containing the value of the 'nixd' section","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/solidlsp/language_servers/nixd_ls.py","lineNumber":266,"sourceCode":"        if not isinstance(config_path_value, str) or not config_path_value.strip():\n            raise ValueError(\"ls_specific_settings.nix.config_path must be a non-empty absolute path\")\n\n        config_path = Path(config_path_value).expanduser()\n        if not config_path.is_absolute():\n            raise ValueError(f\"ls_specific_settings.nix.config_path must be absolute: {config_path_value!r}\")\n\n        try:\n            with config_path.open(encoding=\"utf-8\") as config_file:\n                settings = json.load(config_file)\n        except json.JSONDecodeError as exc:\n            raise ValueError(\n                f\"Invalid JSON in nixd configuration file '{config_path}': {exc.msg} (line {exc.lineno}, column {exc.colno})\"\n            ) from exc\n        except OSError as exc:\n            raise RuntimeError(f\"Failed to read nixd configuration file '{config_path}': {exc}\") from exc\n\n        if not isinstance(settings, dict):\n            raise ValueError(\n                f\"Invalid nixd configuration file '{config_path}': expected a JSON object containing the value of the 'nixd' section\"\n            )\n        return settings\n\n    @staticmethod\n    def _resolve_nixd_configuration_section(settings: dict[str, Any], section: object) -> Any:\n        \"\"\"Resolve a ``nixd`` configuration section from the effective settings.\"\"\"\n        if section == \"nixd\":\n            return deepcopy(settings)\n        if not isinstance(section, str) or not section.startswith(\"nixd.\"):\n            return {}\n\n        value: Any = settings\n        for key in section.removeprefix(\"nixd.\").split(\".\"):\n            if not key or not isinstance(value, dict) or key not in value:\n                return {}\n            value = value[key]\n        return deepcopy(value)","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/solidlsp/language_servers/nixd_ls.py#L248-L284","documentation":"This ValueError is raised when the nixd configuration file parses as valid JSON but its top level is not a JSON object (dict). The library expects the file to contain either a full settings object or the value of the 'nixd' section directly, so an array, string, number, or boolean at the top level is rejected. It is thrown from _load_nixd_settings during server startup.","triggerScenarios":"Calling the nixd language server __init__ with a 'config_path' whose JSON file has a non-object top level, e.g. a JSON array '[...]' or a string, causing isinstance(settings, dict) to fail.","commonSituations":"Hand-written config that starts with '[' instead of '{'; exporting a list of options instead of an object; copy-pasting just the inner value of a key instead of the enclosing object; JSON that is a quoted string.","solutions":["Open the config file and ensure the outermost syntax is a JSON object: { ... }.","If the file currently holds a list of settings, wrap it: { \"nixd\": <the-list's intended structure> } or restructure options into key/value pairs.","Validate the file with a JSON parser/validator (python -m json.tool <path>) and check the top-level type.","If the file is meant to hold only the 'nixd' section value, that value itself must be an object; nest it accordingly."],"exampleFix":"// before (config.json)\n[\n  { \"nixd\": { \"nixpkgs\": { \"expr\": \"import <nixpkgs> {}\" } } }\n]\n// after\n{\n  \"nixd\": { \"nixpkgs\": { \"expr\": \"import <nixpkgs> {}\" } }\n}","handlingStrategy":"validation","validationCode":"import json\n\ndef validate_nixd_config_is_object(path: str) -> dict:\n    with open(path, \"r\", encoding=\"utf-8\") as f:\n        settings = json.load(f)\n    if not isinstance(settings, dict):\n        raise ValueError(\n            f\"{path}: top level must be a JSON object (the 'nixd' section value), \"\n            f\"got {type(settings).__name__}\"\n        )\n    return settings","typeGuard":null,"tryCatchPattern":"try:\n    server = NixdLanguageServer(config_path=path, **common)\nexcept ValueError as e:\n    if \"expected a JSON object\" in str(e):\n        logger.error(\"nixd config %s has non-object top level: %s\", path, e)\n        server = NixdLanguageServer(**common)  # default settings\n    else:\n        raise","preventionTips":["Schema-check the nixd config in CI with a tiny script asserting isinstance(json.load(f), dict).","Remember the file must contain the value of the 'nixd' section, i.e. start with '{'.","Use a JSON editor/linter that shows the root node type.","Add a unit test that loads the shipped default config."],"tags":["nixd","config-file","json","schema-validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}