Unhelpfull error message on corrupted derivation "expected string 'D'" #447

Closed
opened 2024-07-13 11:36:37 +00:00 by pr2502 · 1 comment

Describe the bug

When the nix store is corrupted in such a way that a derivation file (.drv) is empty the parsing fails with broken looking and not very helpful error message:

fetching path input 'path:/nix/store/dk2rpyb6ndvfbf19bkb2plcz5y3k8i5v-source'
error:
       … while evaluating 'strict' to select 'drvPath' on it
         at /builtin/derivation.nix:1:552:
       … while calling the 'derivationStrict' builtin
         at /builtin/derivation.nix:1:208:
       (stack trace truncated; use '--show-trace' to show the full trace)

       error: error parsing derivation '/nix/store/qw0v3wzkvbipjbvbba36f7i3zjqg7n3f-source.drv': error: expected string 'D'

Steps To Reproduce

  1. create any derivation like
    nix-repl> derivation { name = "expected-d-repro"; system = builtins.currentSystem; builder = "builder"; }
    «derivation /nix/store/s1fiwaika47si98h0297sldnqqalyrx2-expected-d-repro.drv»
    
  2. corrupt the derivation
    $ sudo mount -o remount,rw /nix/store
    $ sudo truncate -s0 /nix/store/s1fiwaika47si98h0297sldnqqalyrx2-expected-d-repro.drv
    
  3. attempt to build the corrupted derivation
    $ nix-build /nix/store/s1fiwaika47si98h0297sldnqqalyrx2-expected-d-repro.drv
    error: error parsing derivation '/nix/store/s1fiwaika47si98h0297sldnqqalyrx2-expected-d-repro.drv': error: expected string 'D'
    

Expected behavior

I'd expect a bit more descriptive error message, probably a suggestion to run nix-store --verify-path <drvpath> and maybe even how to fix it? in this case that's nix-store --delete <drvpath> but I'm not sure if that's universally applicable. nix-store --repair-path <drvpath> definitely did not work in this case.

nix --version output

nix (Lix, like Nix) 2.91.0-dev-pre20240705-b6a08a2

## Describe the bug When the nix store is corrupted in such a way that a derivation file (.drv) is empty the parsing fails with broken looking and not very helpful error message: ``` fetching path input 'path:/nix/store/dk2rpyb6ndvfbf19bkb2plcz5y3k8i5v-source' error: … while evaluating 'strict' to select 'drvPath' on it at /builtin/derivation.nix:1:552: … while calling the 'derivationStrict' builtin at /builtin/derivation.nix:1:208: (stack trace truncated; use '--show-trace' to show the full trace) error: error parsing derivation '/nix/store/qw0v3wzkvbipjbvbba36f7i3zjqg7n3f-source.drv': error: expected string 'D' ``` ## Steps To Reproduce 1. create any derivation like ``` nix-repl> derivation { name = "expected-d-repro"; system = builtins.currentSystem; builder = "builder"; } «derivation /nix/store/s1fiwaika47si98h0297sldnqqalyrx2-expected-d-repro.drv» ``` 2. corrupt the derivation ``` $ sudo mount -o remount,rw /nix/store $ sudo truncate -s0 /nix/store/s1fiwaika47si98h0297sldnqqalyrx2-expected-d-repro.drv ``` 3. attempt to build the corrupted derivation ``` $ nix-build /nix/store/s1fiwaika47si98h0297sldnqqalyrx2-expected-d-repro.drv error: error parsing derivation '/nix/store/s1fiwaika47si98h0297sldnqqalyrx2-expected-d-repro.drv': error: expected string 'D' ``` ## Expected behavior I'd expect a bit more descriptive error message, probably a suggestion to run `nix-store --verify-path <drvpath>` and maybe even how to fix it? in this case that's `nix-store --delete <drvpath>` but I'm not sure if that's universally applicable. `nix-store --repair-path <drvpath>` definitely did not work in this case. ## `nix --version` output `nix (Lix, like Nix) 2.91.0-dev-pre20240705-b6a08a2`
Member

This issue was mentioned on Gerrit on the following CLs:

  • commit message in cl/4665 ("libstore/store-api: offer more information about drv parsing errors")
  • commit message in cl/4664 ("libstore/derivations: expand error message for the first misparse")
<!-- GERRIT_LINKBOT: {"cls": [{"backlink": "https://gerrit.lix.systems/c/lix/+/4665", "number": 4665, "kind": "commit message"}, {"backlink": "https://gerrit.lix.systems/c/lix/+/4664", "number": 4664, "kind": "commit message"}], "cl_meta": {"4665": {"change_title": "libstore/store-api: offer more information about drv parsing errors"}, "4664": {"change_title": "libstore/derivations: expand error message for the first misparse"}}} --> This issue was mentioned on Gerrit on the following CLs: * commit message in [cl/4665](https://gerrit.lix.systems/c/lix/+/4665) ("libstore/store-api: offer more information about drv parsing errors") * commit message in [cl/4664](https://gerrit.lix.systems/c/lix/+/4664) ("libstore/derivations: expand error message for the first misparse")
pennae added this to the 2.95 milestone 2025-12-01 14:51:44 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lix-project/lix#447
No description provided.