On Github dominykas / vilniusjs-20150618-errors
By Dominykas Blyžė (@dymonaz), 2015-10-28
var Table = require("throatable"); throw Table;
But then what?
survey: who is logging to server? who is building for 3rd party sites? who has 3rd party snippets?Seriously, browse the web with the developer tools console open logging errors and be truly amazed that the internet ever worked.
@shanselman92% of catastrophic failures are the result of incorrect error handling
Simple Testing Can Prevent Most Critical Failures by Ding Yuan et al, dominykas.net/24Make sure stuff works without JS:
document.createElement is not a function
Function.prototype.apply was called on function (){ /* snip */ }, which is a function and not a function
If you're not doing it yet
window.onerror = function (err, url, line) { ga('send', 'exception', { 'exDescription': line + " " + err }); };
Anything can be thrown - must be able to serialize correctly.
var logMessage = err && err.message ? err.message : "" + err;
> null.toString() TypeError: Cannot read property 'toString' of null > new Error("Damn it").toString() 'Error: Damn it' > new Error("Damn it").message 'Damn it'
At the very least they have useful blogs.
Content-Security-Policy: style-src cdn.example.com; report-uri /_/csp-reports
* no big deal most of the time, but still
function guard (fn) { return function () { try { return fn.apply(this, arguments); } catch (err) { logError(err); throw err; } }; }
Using this for auto-wrapping is probably a bad idea.
People are adding too much shit to their HTML, so let's, like, invent something other, something Accelerated, like for Mobile and Pages, like, which is like HTML, but really not HTML, and they won't add shit there and then it will be, like, very accelerated and mobile and pages stuff.
if (!document.currentScript.getAttribute("crossorigin")) { var script = document.createElement("script"); script.src = document.currentScript.src; script.setAttribute("crossorigin", "anonymous"); document.head.appendChild(script); } else { /* proceed */ }
browserify \ -e bundle/entry.js \ -t uglifyify \ -d | exorcist bundle.js.map > bundle.js
var SourceMapConsumer = require("source-map").SourceMapConsumer; var map = JSON.parse(fs.readFileSync("bundle.js.map")); var smc = new SourceMapConsumer(map); console.log(smc.originalPositionFor({ line: 5, column: 33 }));
{ source: '~/bundle/stuff.js', line: 2, column: 7, name: null }
If you don't throw, it won't have a stack in IE
var error = new Error("snap..."); error.code = "E_SNAP"; throw error;
I don't want to talk about it...
MyCustomError should:
Good custom errors also should:
function CustomError(message) { var temp = Error.call(this, message); temp.name = this.name = 'CustomError'; try { throw temp; } catch (afterThrow) { this.stack = afterThrow.stack; } this.message = temp.message; } CustomError.prototype = Object.create(Error.prototype);
Slides: dominykas.net/25
We're hiring: inwh.se/win
;