elm/libraries/Native/Error.js
Evan Czaplicki b40f2958d4 New convention for storing module values, fixes bug
Before it was not possible to add values to anything except leafs of
the namespace structure.
2013-09-30 01:32:27 -07:00

32 lines
No EOL
1.2 KiB
JavaScript

Elm.Native.Error = {};
Elm.Native.Error.make = function(elm) {
elm.Native = elm.Native || {};
elm.Native.Error = elm.Native.Error || {};
if (elm.Native.Error.values) return elm.Native.Error.values;
var fromString = Elm.Native.JavaScript.make(elm).fromString;
function indent(lines) {
var msg = '';
for (var i = 0; i < lines.length; ++i) {
msg += '<br/>&nbsp; &nbsp; ' + lines[i];
}
return msg;
}
function Case(moduleName, span) {
var msg = indent(['Non-exhaustive pattern match in case-expression.',
'Make sure your patterns cover every case!']);
throw new Error('Runtime error in module ' + moduleName + ' (' + span + '):' + msg);
}
function If(moduleName, span) {
var msg = indent(['Non-exhaustive pattern match in multi-way-if expression.',
'It is best to use \'otherwise\' as the last branch of multi-way-if.']);
throw new Error('Runtime error in module ' + moduleName + ' (' + span + '):' + msg);
}
function raise(str) { throw new Error(fromString(str)); }
return elm.Native.Error.values = { Case: Case, If: If, raise: raise };
};