@@ -84,12 +84,12 @@ func calcSubtreeProof(c CacheReader, leavesToProve Set, subtreeStart Position, w
8484 reader := c .GetLayerReader (0 )
8585 err = reader .Seek (subtreeStart .Index )
8686 if err != nil {
87- return nil , nil , errors . New ("while preparing to traverse subtree: " + err . Error () )
87+ return nil , nil , fmt . Errorf ("while preparing to traverse subtree: %w" , err )
8888 }
8989
9090 _ , additionalProof , additionalLeaves , err = traverseSubtree (reader , width , c .GetHashFunc (), relativeLeavesToProve , nil )
9191 if err != nil {
92- return nil , nil , errors . New ("while traversing subtree: " + err . Error () )
92+ return nil , nil , fmt . Errorf ("while traversing subtree: %w" , err )
9393 }
9494
9595 return additionalProof , additionalLeaves , err
@@ -105,7 +105,7 @@ func traverseSubtree(leafReader LayerReader, width uint64, hash HashFunc, leaves
105105 WithMinHeight (RootHeightFromWidth (width )). // This ensures the correct size tree, even if padding is needed.
106106 Build ()
107107 if err != nil {
108- return nil , nil , nil , errors . New ("while building a tree: " + err . Error () )
108+ return nil , nil , nil , fmt . Errorf ("while building a tree: %w" , err )
109109 }
110110 for i := uint64 (0 ); i < width ; i ++ {
111111 leaf , err := leafReader .ReadNext ()
@@ -117,11 +117,11 @@ func traverseSubtree(leafReader LayerReader, width uint64, hash HashFunc, leaves
117117 leaf = externalPadding
118118 shouldUseExternalPadding = false
119119 } else if err != nil {
120- return nil , nil , nil , errors . New ("while reading a leaf: " + err . Error () )
120+ return nil , nil , nil , fmt . Errorf ("while reading a leaf: %w" , err )
121121 }
122122 err = t .AddLeaf (leaf )
123123 if err != nil {
124- return nil , nil , nil , errors . New ("while adding a leaf: " + err . Error () )
124+ return nil , nil , nil , fmt . Errorf ("while adding a leaf: %w" , err )
125125 }
126126 if leavesToProve [i ] {
127127 provenLeaves = append (provenLeaves , leaf )
@@ -145,11 +145,11 @@ func GetNode(c CacheReader, nodePos Position) ([]byte, error) {
145145 return calcNode (c , nodePos )
146146 }
147147 if err != nil {
148- return nil , errors . New ("while seeking to Position " + nodePos . String () + " in cache: " + err . Error () )
148+ return nil , fmt . Errorf ("while seeking to Position %s in cache: %w" , nodePos , err )
149149 }
150150 currentVal , err := reader .ReadNext ()
151151 if err != nil {
152- return nil , errors . New ("while reading from cache: " + err . Error () )
152+ return nil , fmt . Errorf ("while reading from cache: %w" , err )
153153 }
154154 return currentVal , nil
155155}
@@ -173,7 +173,7 @@ func calcNode(c CacheReader, nodePos Position) ([]byte, error) {
173173 break
174174 }
175175 if err != nil && err != io .EOF {
176- return nil , errors . New ("while seeking to Position " + subtreeStart . String () + " in cache: " + err . Error () )
176+ return nil , fmt . Errorf ("while seeking to Position %s in cache: %w" , subtreeStart , err )
177177 }
178178 if subtreeStart .Height == 0 {
179179 return PaddingValue .value , nil
@@ -184,7 +184,7 @@ func calcNode(c CacheReader, nodePos Position) ([]byte, error) {
184184 width := uint64 (1 ) << (nodePos .Height - subtreeStart .Height )
185185 readerWidth , err := reader .Width ()
186186 if err != nil {
187- return nil , fmt .Errorf ("while getting reader width: %v " , err )
187+ return nil , fmt .Errorf ("while getting reader width: %w " , err )
188188 }
189189 if readerWidth < subtreeStart .Index + width {
190190 paddingPos := Position {
@@ -195,14 +195,14 @@ func calcNode(c CacheReader, nodePos Position) ([]byte, error) {
195195 if err == ErrMissingValueAtBaseLayer {
196196 paddingValue = PaddingValue .value
197197 } else if err != nil {
198- return nil , errors . New ("while calculating ephemeral node at Position " + paddingPos . String () + ": " + err . Error () )
198+ return nil , fmt . Errorf ("while calculating ephemeral node at Position %s: %w" , paddingPos , err )
199199 }
200200 }
201201
202202 // Traverse the subtree.
203203 currentVal , _ , _ , err := traverseSubtree (reader , width , c .GetHashFunc (), nil , paddingValue )
204204 if err != nil {
205- return nil , errors . New ("while traversing subtree for root: " + err . Error () )
205+ return nil , fmt . Errorf ("while traversing subtree for root: %w" , err )
206206 }
207207 return currentVal , nil
208208}
0 commit comments