Allow `tryEval` to catch `import` parse errors
feature
## Is your feature request related to a problem?
I want to use nixd to get options completion for modules I'm working on.
Some of the files that are being edited might be incomplete and cause parsing errors. But I want nixd to still use valid modules to provide option completion.
I've tried writing this code to skip modules that cannot be parsed:
```nix
lib.evalModules {
modules =
if ignore-parse-errors then
allModules
|> builtins.concatMap (
modPath:
let
res = builtins.tryEval (import modPath);
mod = lib.setDefaultModuleLocation modPath res.value;
in
if res.success then [ mod ] else [ ]
)
else
allModules;
};
```
and found out that `builtins.tryEval` cannot catch parsing errors from `import`.
## Proposed solution
Allow `tryEval` to catch `import` parse errors.
## Alternative solutions
nixd uses nix's libexpr. Alternative solution would be to let nixd somehow hook `EvalState::parse` to recover from parsing errors.
## Additional context
Similar issue asking for ability to catch parsing errors in toml and json files: https://github.com/NixOS/nix/issues/8810
## Checklist
<!-- make sure this issue is not redundant or obsolete -->
- [x] checked [latest Nix manual] \([source])
- [x] checked [open feature issues and pull requests] for possible duplicates
- [x] reviewed the [contributing guide]
[latest Nix manual]: https://nix.dev/manual/nix/development/
[source]: https://github.com/NixOS/nix/tree/master/doc/manual/source
[open feature issues and pull requests]: https://github.com/NixOS/nix/labels/feature
[contributing guide]: https://github.com/NixOS/nix/blob/master/CONTRIBUTING.md
---
Add :+1: to [issues you find important](https://github.com/NixOS/nix/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc).
5 条评论