Skip to content

Commit 10777e1

Browse files
lib: in models-universe process wrong path.
1 parent 846e27f commit 10777e1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/lib/models-universe.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const {
1919
NOT_NATIVE_MODEL,
2020
NOT_CONSTRUCTABLE_MODEL,
2121
NOT_INITIALIZED_MODEL,
22+
INVALID_MODULE_PATH,
2223
} = STRINGS;
2324

2425
/**
@@ -44,6 +45,19 @@ export class ModelsUniverse {
4445
}
4546
}
4647

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+
4761
/**
4862
* Returns plugin model. Checks if model is missing then rejects with error.
4963
* Then checks if `path` is starting with github, then grabs the repository name.
@@ -67,7 +81,7 @@ export class ModelsUniverse {
6781
console.log(NOT_NATIVE_MODEL);
6882
}
6983

70-
const pluginModule = await import(path);
84+
const pluginModule = await this.importModuleFrom(path);
7185

7286
if (this.instanceOfModel(pluginModule[model], {model, path})) {
7387
return pluginModule[model];

0 commit comments

Comments
 (0)