on a61faef help sign in
elk/libraries/Native/Error.js
32 lines 1.2 kB history raw
1Elm.Native.Error = {};
2Elm.Native.Error.make = function(elm) {
3 elm.Native = elm.Native || {};
4 elm.Native.Error = elm.Native.Error || {};
5 if (elm.Native.Error.values) return elm.Native.Error.values;
7 var fromString = Elm.Native.JavaScript.make(elm).fromString;
9 function indent(lines) {
10 var msg = '';
11 for (var i = 0; i < lines.length; ++i) {
12 msg += '<br/>&nbsp; &nbsp; ' + lines[i];
13 }
14 return msg;
15 }
17 function Case(moduleName, span) {
18 var msg = indent(['Non-exhaustive pattern match in case-expression.',
19 'Make sure your patterns cover every case!']);
20 throw new Error('Runtime error in module ' + moduleName + ' (' + span + '):' + msg);
21 }
23 function If(moduleName, span) {
24 var msg = indent(['Non-exhaustive pattern match in multi-way-if expression.',
25 'It is best to use \'otherwise\' as the last branch of multi-way-if.']);
26 throw new Error('Runtime error in module ' + moduleName + ' (' + span + '):' + msg);
27 }
29 function raise(str) { throw new Error(fromString(str)); }
31 return elm.Native.Error.values = { Case: Case, If: If, raise: raise };
32};