report uncaught errors

This commit is contained in:
Leo Horie 2016-07-15 22:56:29 -04:00
parent e4a16d3bf4
commit 264741f2f5
3 changed files with 29 additions and 6 deletions

View file

@ -55,7 +55,10 @@ function updateState(stream, value, error) {
if (recovered === HALT) return
updateValues(stream, recovered, undefined)
}
catch (e) {updateValues(stream, undefined, e)}
catch (e) {
updateValues(stream, undefined, e)
reportUncaughtError(stream, e)
}
}
else updateValues(stream, value, error)
stream._state.changed = true
@ -78,6 +81,7 @@ function updateDependency(stream, mustSync) {
}
catch (e) {
updateState(stream, undefined, e)
reportUncaughtError(stream, e)
}
}
}
@ -93,6 +97,13 @@ function finalize(stream) {
stream._state.changed = false
for (var id in stream._state.deps) stream._state.deps[id]._state.changed = false
}
function reportUncaughtError(stream, e) {
if (Object.keys(stream._state.deps).length === 0) {
setTimeout(function() {
if (Object.keys(stream._state.deps).length === 0) console.error(e)
}, 0)
}
}
function run(fn) {
var self = createStream(), stream = this
return initDependency(self, [stream], function() {
@ -1041,7 +1052,7 @@ var autoredraw = function(root, renderer, pubsub, callback) {
var run = throttle(callback)
if (renderer != null) {
renderer.setEventCallback(function(e) {
if (e.redraw !== false) run()
if (e.redraw !== false) pubsub.publish()
})
}
if (pubsub != null) {
@ -1068,7 +1079,7 @@ m.route = function($window, renderer, pubsub) {
else {
renderer.render(root, Node(payload, null, args, undefined, undefined, undefined))
}
}, function(path, params) {
}, function() {
router.setPath(defaultRoute, null, {replace: true})
})
autoredraw(root, renderer, pubsub, replay)
@ -1077,6 +1088,7 @@ m.route = function($window, renderer, pubsub) {
route.prefix = router.setPrefix
route.set = router.setPath
route.get = router.getPath
return route
}(window, renderService, redrawService)
m.mount = function(renderer, pubsub) {

View file

@ -58,7 +58,10 @@ function updateState(stream, value, error) {
if (recovered === HALT) return
updateValues(stream, recovered, undefined)
}
catch (e) {updateValues(stream, undefined, e)}
catch (e) {
updateValues(stream, undefined, e)
reportUncaughtError(stream, e)
}
}
else updateValues(stream, value, error)
stream._state.changed = true
@ -81,6 +84,7 @@ function updateDependency(stream, mustSync) {
}
catch (e) {
updateState(stream, undefined, e)
reportUncaughtError(stream, e)
}
}
}
@ -96,6 +100,13 @@ function finalize(stream) {
stream._state.changed = false
for (var id in stream._state.deps) stream._state.deps[id]._state.changed = false
}
function reportUncaughtError(stream, e) {
if (Object.keys(stream._state.deps).length === 0) {
setTimeout(function() {
if (Object.keys(stream._state.deps).length === 0) console.error(e)
}, 0)
}
}
function run(fn) {
var self = createStream(), stream = this

View file

@ -312,7 +312,7 @@ o.spec("stream", function() {
o("error.map works", function() {
var stream = Stream.stream(1)
var mappedFromError = stream.error.map(function(value) {
return "from" + value.message
if (value) return "from" + value.message
})
o(mappedFromError()).equals(undefined)
@ -382,7 +382,7 @@ o.spec("stream", function() {
var a = Stream.stream(1)
var b = Stream.combine(function(a) {throw new Error("error from b")}, [a])
var c = Stream.combine(function(a) {throw new Error("error from c")}, [a])
var d = Stream.combine(function(a, b) {return 2}, [a, b])
var d = Stream.combine(function(b, c) {return 2}, [b, c])
o(d()).equals(undefined)
o(d.error().message).equals("error from b")