Skip to content

Commit 72fb7e0

Browse files
committed
Delay "compile" Node.js functions so syntax errors are not startup errors but are instead reported in the Dashboard etc. as invocation errors.
1 parent c250632 commit 72fb7e0

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/WebJobs.Script/Description/NodeFunctionInvoker.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ namespace Microsoft.Azure.WebJobs.Script
1919
// TODO: make this internal
2020
public class NodeFunctionInvoker : IFunctionInvoker
2121
{
22-
private readonly Func<object, Task<object>> _scriptFunc;
22+
private Func<object, Task<object>> _scriptFunc;
2323
private static string FunctionTemplate;
2424
private readonly Collection<Binding> _inputBindings;
2525
private readonly Collection<Binding> _outputBindings;
2626
private readonly string _triggerParameterName;
27+
private readonly string _script;
2728

2829
static NodeFunctionInvoker()
2930
{
@@ -34,13 +35,26 @@ static NodeFunctionInvoker()
3435
}
3536
}
3637

38+
private Func<object, Task<object>> ScriptFunc
39+
{
40+
get
41+
{
42+
if (_scriptFunc == null)
43+
{
44+
// We delay create the script function so any syntax errors in
45+
// the function will be reported to the Dashboard as an invocation
46+
// error rather than a host startup error
47+
_scriptFunc = Edge.Func(_script);
48+
}
49+
return _scriptFunc;
50+
}
51+
}
52+
3753
internal NodeFunctionInvoker(string triggerParameterName, string scriptFilePath, Collection<Binding> inputBindings, Collection<Binding> outputBindings)
3854
{
3955
_triggerParameterName = triggerParameterName;
4056
scriptFilePath = scriptFilePath.Replace('\\', '/');
41-
string script = string.Format(FunctionTemplate, scriptFilePath);
42-
_scriptFunc = Edge.Func(script);
43-
57+
_script = string.Format(FunctionTemplate, scriptFilePath);
4458
_inputBindings = inputBindings;
4559
_outputBindings = outputBindings;
4660
}
@@ -87,7 +101,7 @@ public async Task Invoke(object[] parameters)
87101
context["output"] = output;
88102
}
89103

90-
await _scriptFunc(context);
104+
await ScriptFunc(context);
91105

92106
// process output bindings
93107
if (functionOutput != null)

0 commit comments

Comments
 (0)