on master help sign in
Show nicer error messages when module initialization fails due to invalid port values
2f38eecEvan Czaplicki
libraries/Native/Ports.js+10−2
@@ -48,10 +48,18 @@ Elm.Native.Ports.make = function(elm) {
48 "' was not given an input!");
48 "' was not given an input!");
49 }
49 }
50 elm.ports.uses[name] += 1;
50 elm.ports.uses[name] += 1;
51+ try {
51− return converter(value);
52+ return converter(value);
53+ } catch(e) {
54+ throw new Error("Initialization Error on port '" + name + "': \n" + e.message);
55+ }
52 }
56 }
53 function portOut(name, converter, value) {
57 function portOut(name, converter, value) {
58+ try {
54− elm.ports.outgoing[name] = converter(value);
59+ elm.ports.outgoing[name] = converter(value);
60+ } catch(e) {
61+ throw new Error("Initialization Error on port '" + name + "': \n" + e.message);
62+ }
55 return value;
63 return value;
56 }
64 }
57
65