Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

packindex: add verbose reporting of outOfRange errors

  • Loading branch information...
commit 96e49b607a05bb9212f1efdc67a4e381f8025c9c 1 parent 7b35b60
Conrad Parker authored

Showing 1 changed file with 15 additions and 14 deletions. Show diff stats Hide diff stats

  1. +15 14 Git/PackIndex.hs
29 Git/PackIndex.hs
@@ -60,43 +60,44 @@ idxSize IDX2{..} = idx2Size
60 60
61 61 -- | Nth SHA1
62 62 idxSha1 :: IDX -> Int -> IO BS.ByteString
63   -idxSha1 IDX1{..} n
64   - | n >= idx1Size = outOfRange
  63 +idxSha1 idx@IDX1{..} n
  64 + | n >= idx1Size = outOfRange idx n "(v1) SHA1"
65 65 | otherwise = do
66 66 let cs = idx1Offsets `plusPtr` (4 + (n * 24))
67 67 BS.packCStringLen (cs, 20)
68   -idxSha1 IDX2{..} n
69   - | n >= idx2Size = outOfRange
  68 +idxSha1 idx@IDX2{..} n
  69 + | n >= idx2Size = outOfRange idx n "SHA1"
70 70 | otherwise = do
71 71 let cs = idx2SHA1s `plusPtr` (n * 20)
72 72 BS.packCStringLen (cs, 20)
73 73
74 74 -- | Nth CRC
75 75 idxCRC :: IDX -> Int -> IO (Maybe Word32)
76   -idxCRC IDX1{..} n
77   - | n >= idx1Size = outOfRange
  76 +idxCRC idx@IDX1{..} n
  77 + | n >= idx1Size = outOfRange idx n "(v1) CRC"
78 78 | otherwise = return Nothing
79   -idxCRC IDX2{..} n
80   - | n >= idx2Size = outOfRange
  79 +idxCRC idx@IDX2{..} n
  80 + | n >= idx2Size = outOfRange idx n "CRC"
81 81 | otherwise = do
82 82 BE crc <- peekElemOff idx2CRCs n
83 83 return (Just crc)
84 84
85 85 -- | Nth offset
86 86 idxOffset :: IDX -> Int -> IO FileOffset
87   -idxOffset IDX1{..} n
88   - | n >= idx1Size = outOfRange
  87 +idxOffset idx@IDX1{..} n
  88 + | n >= idx1Size = outOfRange idx n "(v1) Offset"
89 89 | otherwise = do
90 90 BE off <- peekByteOff idx1Offsets (n * 24)
91 91 return . fromIntegral $ (off :: Word32)
92   -idxOffset IDX2{..} n
93   - | n >= idx2Size = outOfRange
  92 +idxOffset idx@IDX2{..} n
  93 + | n >= idx2Size = outOfRange idx n "Offset"
94 94 | otherwise = do
95 95 BE off <- peekElemOff idx2Offsets n
96 96 return . fromIntegral $ off
97 97
98   -outOfRange :: IO a
99   -outOfRange = error "Index out of range"
  98 +outOfRange :: IDX -> Int -> String -> IO a
  99 +outOfRange idx n s = error $ printf "%s: %s index %d out of range (size %d)"
  100 + (idxPack idx) s n (idxSize idx)
100 101
101 102 ------------------------------------------------------------
102 103

0 comments on commit 96e49b6

Please sign in to comment.
Something went wrong with that request. Please try again.