1
1
import * as dagPb from '@ipld/dag-pb'
2
- import errCode from 'err-code'
3
2
import { UnixFS } from 'ipfs-unixfs'
4
3
import map from 'it-map'
5
4
import parallel from 'it-parallel'
@@ -8,6 +7,7 @@ import { type Pushable, pushable } from 'it-pushable'
8
7
import * as raw from 'multiformats/codecs/raw'
9
8
import PQueue from 'p-queue'
10
9
import { CustomProgressEvent } from 'progress-events'
10
+ import { NotUnixFSError , OverReadError , UnderReadError } from '../../../errors.js'
11
11
import extractDataFromBlock from '../../../utils/extract-data-from-block.js'
12
12
import validateOffsetAndLength from '../../../utils/validate-offset-and-length.js'
13
13
import type { ExporterOptions , UnixfsV1FileContent , UnixfsV1Resolver , ReadableStorage , ExportProgress , ExportWalk } from '../../../index.js'
@@ -23,15 +23,15 @@ async function walkDAG (blockstore: ReadableStorage, node: dagPb.PBNode | Uint8A
23
23
}
24
24
25
25
if ( node . Data == null ) {
26
- throw errCode ( new Error ( 'no data in PBNode' ) , 'ERR_NOT_UNIXFS ')
26
+ throw new NotUnixFSError ( 'no data in PBNode' )
27
27
}
28
28
29
29
let file : UnixFS
30
30
31
31
try {
32
32
file = UnixFS . unmarshal ( node . Data )
33
33
} catch ( err : any ) {
34
- throw errCode ( err , 'ERR_NOT_UNIXFS' )
34
+ throw new NotUnixFSError ( err . message )
35
35
}
36
36
37
37
// might be a unixfs `raw` node or have data on intermediate nodes
@@ -47,7 +47,7 @@ async function walkDAG (blockstore: ReadableStorage, node: dagPb.PBNode | Uint8A
47
47
const childOps : Array < { link : dagPb . PBLink , blockStart : bigint } > = [ ]
48
48
49
49
if ( node . Links . length !== file . blockSizes . length ) {
50
- throw errCode ( new Error ( 'Inconsistent block sizes and dag links' ) , 'ERR_NOT_UNIXFS ')
50
+ throw new NotUnixFSError ( 'Inconsistent block sizes and dag links' )
51
51
}
52
52
53
53
for ( let i = 0 ; i < node . Links . length ; i ++ ) {
@@ -98,7 +98,7 @@ async function walkDAG (blockstore: ReadableStorage, node: dagPb.PBNode | Uint8A
98
98
child = block
99
99
break
100
100
default :
101
- queue . end ( errCode ( new Error ( `Unsupported codec: ${ link . Hash . code } ` ) , 'ERR_NOT_UNIXFS' ) )
101
+ queue . end ( new NotUnixFSError ( `Unsupported codec: ${ link . Hash . code } ` ) )
102
102
return
103
103
}
104
104
@@ -171,7 +171,7 @@ const fileContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth,
171
171
172
172
if ( read > wanted ) {
173
173
queue . end ( )
174
- throw errCode ( new Error ( 'Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect' ) , 'ERR_OVER_READ ')
174
+ throw new OverReadError ( 'Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect' )
175
175
}
176
176
177
177
if ( read === wanted ) {
@@ -188,7 +188,7 @@ const fileContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth,
188
188
}
189
189
190
190
if ( read < wanted ) {
191
- throw errCode ( new Error ( 'Traversed entire DAG but did not read enough bytes' ) , 'ERR_UNDER_READ ')
191
+ throw new UnderReadError ( 'Traversed entire DAG but did not read enough bytes' )
192
192
}
193
193
}
194
194
0 commit comments