ftlabs / fruitmachine-media

FruitMachine helper that allows different setup and teardown callbacks to be called based on media queries
MIT License
6 stars 3 forks source link

Log errors to the console. #13

Open AdaRoseCannon opened 10 years ago

matthew-andrews commented 10 years ago

As you well know, console ist nicht immer definiert ;-) so this might be a problem. Maybe changing this to be*:-

.catch(function(err) {
  throw err;
});

* Note: this may be a terrible idea.

This is actually quite timely we're discussing within Origami how best to catch errors.

There's talk of a very simple o-catch component that converts errors into DOM events... the idea is each component would then emit errors that could be listened to by an error handler on the document body which would then either display those errors to the console (in dev) or submit them for aggregation (on live).

Wonder if @pornel wouldn't mind commenting.

kornelski commented 10 years ago

I don't get this:

.catch(function(err) {
  throw err;
});

isn't that a no-op?

We don't have oErrors ready yet, so for this PR I'd just suggest adding if (window.console).

AdaRoseCannon commented 10 years ago

Kornel no, that catch is the catch for the promise above it. The throw is then caught by the window.

Promise.all([new Promise(function (resolve, reject) {rtyui()})]).catch(function (e) {throw e});

^^^^ Throws no error!

AdaRoseCannon commented 10 years ago

I've asked Jake and from reading the links he has sent me this is a bit of controversial issue.

https://github.com/domenic/promises-unwrapping/issues/19 https://code.google.com/p/v8/issues/detail?id=3093

One very ugly solution I saw was to throw the error in a ansync function since we have setImmediate I guess we would do setImmediate(function () {throw err;})

I think the oError would be the ideal solution. Unfortunately the solution to pause on the uncaught errors in devtools does not work in iOS for me since pausing code execution crashes safari and ios_debgger proxy.

matthew-andrews commented 10 years ago

I'm fine with this as is - and actually on reflection I prefer it without the if (console) check.

Can we just add a // TODO to switch to o-catch once it's ready?