diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2013-04-12 18:48:14 +0200 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2013-05-06 16:22:25 +0200 |
commit | f1a83b6fdc949b624e717c23768ed9fbcbf572b6 (patch) | |
tree | 2d90c7ed98c275e831a2fac50311b9626bb3073c | |
parent | ffeafa6ec2974de5e3f2303fa8ffccf1638e9254 (diff) | |
download | freeipa-f1a83b6fdc949b624e717c23768ed9fbcbf572b6.tar.gz freeipa-f1a83b6fdc949b624e717c23768ed9fbcbf572b6.tar.xz freeipa-f1a83b6fdc949b624e717c23768ed9fbcbf572b6.zip |
Builder: do not break on expected errors
https://fedorahosted.org/freeipa/ticket/3235
-rw-r--r-- | install/ui/src/freeipa/_base/Builder.js | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/install/ui/src/freeipa/_base/Builder.js b/install/ui/src/freeipa/_base/Builder.js index 464a2c09d..75b1a38d3 100644 --- a/install/ui/src/freeipa/_base/Builder.js +++ b/install/ui/src/freeipa/_base/Builder.js @@ -210,6 +210,14 @@ define(['dojo/_base/declare', var cs = construction_spec, obj = null; + if (!(cs.factory && typeof cs.factory === 'function') && + !(cs.ctor && typeof cs.ctor === 'function')) { + throw { + error: 'Build error: missing or invalid ctor or factory', + spec: cs + }; + } + // deep clone to prevent modification of original spec by preops cs.spec = construct.clone(cs.spec); @@ -223,15 +231,20 @@ define(['dojo/_base/declare', this.spec_mod.mod(cs.spec, cs.spec); this.spec_mod.del_rules(cs.spec); - if (cs.factory && typeof cs.factory === 'function') { - obj = cs.factory(cs.spec); - } else if (cs.ctor && typeof cs.ctor === 'function') { - obj = new cs.ctor(cs.spec); - } else { - throw { - error: 'Build error: missing or invalid ctor or factory', - spec: cs - }; + try { + if (cs.factory) { + obj = cs.factory(cs.spec); + } else { + obj = new cs.ctor(cs.spec); + } + } catch (e) { + if (e.expected) { + // expected exceptions thrown by builder just mean that + // object is not to be built + obj = null; + } else { + throw e; + } } obj = this._run_post_ops(this.post_ops, obj, cs.spec, context); |