Skip to content

Commit c99ff43

Browse files
Taritsyndustinsoftware
authored andcommitted
Catch all the JavaScript Engine Switcher's exceptions (#646)
1 parent a1be190 commit c99ff43

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

src/React.Core/JavaScriptEngineFactory.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,16 @@ private void LoadUserScripts(IJsEngine engine)
185185
engine.ExecuteFile(_fileSystem, file);
186186
}
187187
}
188-
catch (JsScriptException ex)
188+
catch (JsException ex)
189189
{
190190
// We can't simply rethrow the exception here, as it's possible this is running
191191
// on a background thread (ie. as a response to a file changing). If we did
192192
// throw the exception here, it would terminate the entire process. Instead,
193193
// save the exception, and then just rethrow it later when getting the engine.
194194
_scriptLoadException = new ReactScriptLoadException(string.Format(
195-
"Error while loading \"{0}\": {1}\r\nLine: {2}\r\nColumn: {3}",
195+
"Error while loading \"{0}\": {1}",
196196
file,
197-
ex.Message,
198-
ex.LineNumber,
199-
ex.ColumnNumber
197+
ex.Message
200198
));
201199
}
202200
catch (IOException ex)

src/React.Core/ReactComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public virtual void RenderHtml(TextWriter writer, bool renderContainerOnly = fal
195195
return;
196196
}
197197
}
198-
catch (JsRuntimeException ex)
198+
catch (JsException ex)
199199
{
200200
if (exceptionHandler == null)
201201
{

src/React.Core/ReactEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ protected virtual void EnsureUserScriptsLoaded()
209209
Engine.Execute(contents, file);
210210
}
211211
}
212-
catch (JsScriptException ex)
212+
catch (JsException ex)
213213
{
214214
throw new ReactScriptLoadException(string.Format(
215215
"Error while loading \"{0}\": {1}",

tests/React.Tests/Core/JavaScriptEngineFactoryTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ public void ShouldThrowScriptErrorIfReactFails()
466466
var factory = CreateFactory(config, cache, fileSystem, () => jsEngine.Object);
467467

468468
var ex = Assert.Throws<ReactScriptLoadException>(() => factory.GetEngineForCurrentThread());
469-
Assert.Equal("Error while loading \"foo.js\": Fail\r\nLine: 42\r\nColumn: 911", ex.Message);
469+
Assert.Equal("Error while loading \"foo.js\": Fail", ex.Message);
470470
}
471471

472472
[Fact]
@@ -489,7 +489,7 @@ public void ShouldCatchErrorsWhileLoadingScripts()
489489
var factory = CreateFactory(config, cache, fileSystem, () => jsEngine.Object);
490490

491491
var ex = Assert.Throws<ReactScriptLoadException>(() => factory.GetEngineForCurrentThread());
492-
Assert.Equal("Error while loading \"foo.js\": Fail\r\nLine: 42\r\nColumn: 911", ex.Message);
492+
Assert.Equal("Error while loading \"foo.js\": Fail", ex.Message);
493493
}
494494

495495
[Fact]

0 commit comments

Comments
 (0)