File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ const {
19
19
NOT_NATIVE_MODEL ,
20
20
NOT_CONSTRUCTABLE_MODEL ,
21
21
NOT_INITIALIZED_MODEL ,
22
+ INVALID_MODULE_PATH ,
22
23
} = STRINGS ;
23
24
24
25
/**
@@ -44,6 +45,19 @@ export class ModelsUniverse {
44
45
}
45
46
}
46
47
48
+ /**
49
+ * Imports module by given `path`.
50
+ */
51
+ private async importModuleFrom ( path : string ) {
52
+ try {
53
+ const module = await import ( path ) ;
54
+
55
+ return module ;
56
+ } catch ( error ) {
57
+ throw new ModelInitializationError ( INVALID_MODULE_PATH ( path ) ) ;
58
+ }
59
+ }
60
+
47
61
/**
48
62
* Returns plugin model. Checks if model is missing then rejects with error.
49
63
* Then checks if `path` is starting with github, then grabs the repository name.
@@ -67,7 +81,7 @@ export class ModelsUniverse {
67
81
console . log ( NOT_NATIVE_MODEL ) ;
68
82
}
69
83
70
- const pluginModule = await import ( path ) ;
84
+ const pluginModule = await this . importModuleFrom ( path ) ;
71
85
72
86
if ( this . instanceOfModel ( pluginModule [ model ] , { model, path} ) ) {
73
87
return pluginModule [ model ] ;
You can’t perform that action at this time.
0 commit comments