on master help sign in
Show nicer error messages when module initialization fails due to invalid port values
commit2f38eec8f8235e10fef76173385e58bf12a017d9 authorEvan Czaplicki <info@elm-lang.org> dateTue 14 Jan 2014, 11:49 (13 years ago) parentcbf0b60
1 file changed+10−2
libraries/Native/Ports.js+10−2
libraries/Native/Ports.js+10−2
@@ -48,10 +48,18 @@ Elm.Native.Ports.make = function(elm) {
4848 "' was not given an input!");
4949 }
5050 elm.ports.uses[name] += 1;
51− return converter(value);
51+ try {
52+ return converter(value);
53+ } catch(e) {
54+ throw new Error("Initialization Error on port '" + name + "': \n" + e.message);
55+ }
5256 }
5357 function portOut(name, converter, value) {
54− elm.ports.outgoing[name] = converter(value);
58+ try {
59+ elm.ports.outgoing[name] = converter(value);
60+ } catch(e) {
61+ throw new Error("Initialization Error on port '" + name + "': \n" + e.message);
62+ }
5563 return value;
5664 }
5765