Skip to content

Commit 104afeb

Browse files
committed
Solve minor bugs in fail paths for nodejs require.
1 parent 7e3d58c commit 104afeb

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

source/loaders/cs_loader/netcore/source/MetacallEntryPoint.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ namespace CSLoader
1818
public static class MetacallEntryPoint
1919
{
2020
private static LoaderBase loader = null;
21+
private static ConsoleLog log = new ConsoleLog();
2122

2223
static MetacallEntryPoint()
2324
{
24-
25-
var log = new ConsoleLog();
26-
2725
log.Info("CSLoader static initialization");
2826

2927
#if NETCOREAPP1_0 || NETCOREAPP1_1 || NETCOREAPP1_2
@@ -45,7 +43,13 @@ public static bool Load(string source)
4543

4644
public static bool Load(string[] files)
4745
{
48-
return loader.LoadFromSourceFunctions(files.Select(x => System.IO.File.ReadAllText(x)).ToArray());
46+
try {
47+
return loader.LoadFromSourceFunctions(files.Select(x => System.IO.File.ReadAllText(x)).ToArray());
48+
} catch (FileNotFoundException ex) {
49+
// TODO: Implement error handling
50+
log.Info(ex.Message);
51+
return false;
52+
}
4953
}
5054

5155
public static ReflectFunction[] GetFunctionsInternal()

source/ports/node_port/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,15 @@ mod.prototype.require = function (name) {
195195
/* NodeJS Loader */
196196
js: 'node',
197197
node: 'node',
198+
199+
/* TODO: TypeScript Loader is not supported to run with NodeJS Loader at the same time yet */
200+
198201
/* TypeScript Loader */
202+
/*
199203
ts: 'ts',
200204
jsx: 'ts',
201205
tsx: 'ts',
206+
*/
202207

203208
/* Note: By default js extension uses NodeJS loader instead of JavaScript V8 */
204209
/* Probably in the future we can differenciate between them, but it is not trivial */

source/ports/node_port/test/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ describe('metacall', () => {
4242
});
4343
});
4444

45+
describe('fail', () => {
46+
it('require', () => {
47+
assert.strictEqual(require('./asd.invalid'), undefined);
48+
});
49+
});
50+
4551
describe('load', () => {
4652
it('metacall_load_from_file (py)', () => {
4753
assert.strictEqual(metacall_load_from_file('py', [ 'helloworld.py' ] ), undefined);

source/tests/metacall_node_port_test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ if(OPTION_BUILD_LOADERS_COB)
135135
endif()
136136

137137
add_dependencies(${target}
138+
node_port
138139
node_loader
139140
mock_loader
140141
py_loader

0 commit comments

Comments
 (0)