elm/libraries/Native/Error.js

32 lines
1.1 KiB
JavaScript
Raw Normal View History

Elm.Native.Error = function(elm) {
'use strict';
elm.Native = elm.Native || {};
if (elm.Native.Error) return elm.Native.Error;
var fromString = Elm.Native.JavaScript(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 = { Case: Case, If: If, raise: raise };
};