Skip to content

Commit ec18ca6

Browse files
committed
Fix crash when a store path does not have a signature
1 parent a3568b8 commit ec18ca6

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 0.6.2 - 2025-02-25:
4+
5+
* fix: Fix a failure when the store path does not have a signature. (thanks @minhtrancccp, issue [#114]))
6+
7+
[#114]: https://github.com/utdemir/nix-tree/issues/114
8+
39
## 0.6.1 - 2025-01-25:
410

511
* chore: Relax brick upper bound to work with newer Stackage snapshot

src/NixTree/StorePath.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module NixTree.StorePath
2020
)
2121
where
2222

23-
import Data.Aeson (FromJSON (..), Value (..), decode, (.:))
23+
import Data.Aeson (FromJSON (..), Value (..), decode, eitherDecode, (.!=), (.:), (.:?))
2424
import qualified Data.Aeson.Key as K
2525
import qualified Data.Aeson.KeyMap as KM
2626
import Data.Aeson.Types (Parser)
@@ -163,7 +163,7 @@ data PathInfoOptions = PathInfoOptions
163163
getPathInfo :: NixStore -> NixVersion -> PathInfoOptions -> NonEmpty Installable -> IO (NonEmpty (StorePath s (StoreName s) ()))
164164
getPathInfo nixStore nixVersion options names = do
165165
infos <-
166-
decode @NixPathOutput
166+
eitherDecode @NixPathOutput
167167
<$> readProcessStdout_
168168
( proc
169169
"nix"
@@ -183,7 +183,7 @@ getPathInfo nixStore nixVersion options names = do
183183
++ map (toString . installableToText) (toList names)
184184
)
185185
)
186-
>>= maybe (fail "Failed parsing nix path-info output.") return
186+
>>= either (\e -> fail $ "Failed parsing nix path-info output: " ++ show e) return
187187
>>= mapM assertValidInfo . npoResults
188188
>>= maybe (fail "invariant violation: getPathInfo returned []") return . nonEmpty
189189

@@ -405,7 +405,7 @@ parse2_18 (Object obj) =
405405
<$> obj .: "path"
406406
<*> obj .: "narSize"
407407
<*> obj .: "references"
408-
<*> obj .: "signatures"
408+
<*> (obj .:? "signatures" .!= [])
409409
)
410410
)
411411
<|> ( do
@@ -423,7 +423,7 @@ parse2_19 (path, Object obj) =
423423
path
424424
<$> obj .: "narSize"
425425
<*> obj .: "references"
426-
<*> obj .: "signatures"
426+
<*> (obj .:? "signatures" .!= [])
427427
)
428428
parse2_19 (path, Null) = return $ NixPathInfoInvalid path
429429
parse2_19 (_, _) = fail "Expecting an object or null"

0 commit comments

Comments
 (0)