This repository was archived by the owner on Sep 14, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -5,13 +5,40 @@ import { NetSpec } from "../nets/mod.ts"
5
5
6
6
const $nets = $ . record ( $ . instance ( NetSpec as new ( ) => NetSpec , $ . tuple ( ) , ( _ : NetSpec ) => [ ] ) )
7
7
8
+ const $tsDiagnostics = $ . field ( "diagnosticCodes" , $ . array ( $ . u32 ) )
9
+
8
10
export async function resolveNets ( maybeNetsPath ?: string ) : Promise < Record < string , NetSpec > > {
9
11
const resolvedNetsPath = await resolveNetsPath ( maybeNetsPath )
10
12
if ( resolvedNetsPath . endsWith ( ".ts" ) ) {
11
13
await register ( )
12
14
}
13
15
// shimmed by dnt
14
- let nets = await _import ( resolvedNetsPath )
16
+ let nets = await ( async ( ) => {
17
+ try {
18
+ return await _import ( resolvedNetsPath )
19
+ } catch ( err ) {
20
+ let errorMessage = `Failed to import nets file ${ resolvedNetsPath } `
21
+ if ( $ . is ( $tsDiagnostics , err ) ) {
22
+ for ( const code of new Set ( err . diagnosticCodes ) ) {
23
+ errorMessage += `: Typescript compiler error TS${ code } `
24
+ switch ( code ) {
25
+ case 2305 :
26
+ errorMessage += ": Did you forget to import from \"capi/nets\"?"
27
+ break
28
+ case 2307 :
29
+ errorMessage +=
30
+ ": Did you set your tsconfig module to \"ESNext\" and moduleResolution to \"node16\"?"
31
+ break
32
+ default :
33
+ break
34
+ }
35
+ }
36
+ } else {
37
+ console . error ( err )
38
+ }
39
+ throw new Error ( errorMessage )
40
+ }
41
+ } ) ( )
15
42
if ( "default" in nets ) nets = nets . default
16
43
$ . assert ( $nets , nets )
17
44
for ( const key in nets ) nets [ key ] ! . name = key
You can’t perform that action at this time.
0 commit comments