Skip to content

Commit

Permalink
BUGFIX: Misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hash-bang committed Apr 10, 2019
1 parent 35895ac commit f0081d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
8 changes: 4 additions & 4 deletions cli/i3.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Promise.resolve({}) // Setup waterfall session (gets populated at each successiv
} else {
i3.log(1, `Retrieving manifest from "${i3.settings.action}"`);
return i3.manifest.get(i3.settings.action)
.catch(e => { throw `Cannot find I3 compatible app at "${i3.settings.action}"` })
.catch(e => { throw new Error(`Cannot find I3 compatible app at "${i3.settings.action}"`) })
.then(manifest => {
_.set(session, 'manifest', manifest);
_.set(session, 'worker', {path: fspath.resolve(i3.settings.action)});
Expand Down Expand Up @@ -266,12 +266,12 @@ Promise.resolve({}) // Setup waterfall session (gets populated at each successiv
args: _([
'run', // Docker sub-command

// Docker options including mounts
session.manifest.worker.mount ? ['--volume', `${session.workspace.path}:${session.manifest.worker.mount}`] : '',

// Environment variables
entryEnv.length ? entryEnv : false,

// Docker options including mounts
session.manifest.worker.mount ? ['--volume', `${session.workspace.path}:${session.manifest.worker.mount}`] : '',

// Main container name
session.manifest.worker.container,

Expand Down
35 changes: 15 additions & 20 deletions cli/lib/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var i3Manifest = function i3Manifest(i3) {
.then(contents => ({path: `${path}/${file}`, contents}))
.catch(e => Promise.resolve())
))
.then(files => files.find(f => f)) // Find first matching
.then(files => files.find(f => _.isObject(f))) // Find first matching
.then(file => ({path: file.path, ...JSON.parse(file.contents)}));


Expand All @@ -33,7 +33,7 @@ var i3Manifest = function i3Manifest(i3) {
.then(m => {
var errs = [];

if (!m) throw new Error('Not a JSON file');
if (!m) Promise.reject('Not a JSON file');

// Check for missing fields (dotted notation) {{{
['name', 'version', 'description', 'license', 'inputs', 'outputs', 'worker', 'worker.container']
Expand All @@ -42,16 +42,9 @@ var i3Manifest = function i3Manifest(i3) {
.forEach(text => err.push(text))
// }}}

// Check for empty input / output blocks {{{
['inputs', 'outputs']
.filter(field => !_.isObject(m[field]) || !_.isEmpty(m[field]))
.map(field => `${field} must be a non-empty array or object`)
.forEach(text => err.push(text))
// }}}

// Check inputs {{{
if (!_.isUndefined(m.inputs)) {
err.push('The input array must be specified, even if it is an empty array');
if (_.isUndefined(m.inputs)) {
errs.push('The input array must be specified, even if it is an empty array');
} else {
(_.castArray(m.inputs)).forEach((i, index) => {
['type'].forEach(f => {
Expand All @@ -69,13 +62,13 @@ var i3Manifest = function i3Manifest(i3) {
// }}}

// Check worker {{{
if (['docker', 'url'].includes(m.worker.type)) throw new Error('worker.container can only be "docker" or "url" at this point');
if (m.worker.type == 'docker' && !_.has(m, 'worker.container')) throw new Error('If worker.container == "docker", worker.container must be specified');
if (m.worker.type == 'url' && !_.has(m, 'worker.url')) throw new Error('If worker.container == "url", worker.url must be specified');
if (m.command && !_.isArray(m.command)) throw new Error('worker.command must be an array');
if (m.command && m.command.every(i => _.isString(i))) throw new Error('worker.command must be an array of strings only');
if (m.environment && !_.isPlainObject(m.environment)) throw new Error('worker.envionment must be an object');
if (m.environment && _.every(m.environment, (v, k) => _.isString(v) && _.isString(k))) throw new Error('worker.envionment must be an object of string key / values only');
if (!['docker', 'url'].includes(m.worker.type)) Promise.reject('worker.type can only be "docker" or "url" at this point');
if (m.worker.type == 'docker' && !_.has(m, 'worker.container')) Promise.reject('If worker.container == "docker", worker.container must be specified');
if (m.worker.type == 'url' && !_.has(m, 'worker.url')) Promise.reject('If worker.container == "url", worker.url must be specified');
if (m.command && !_.isArray(m.command)) Promise.reject('worker.command must be an array');
if (m.command && m.command.every(i => _.isString(i))) Promise.reject('worker.command must be an array of strings only');
if (m.environment && !_.isPlainObject(m.environment)) Promise.reject('worker.envionment must be an object');
if (m.environment && _.every(m.environment, (v, k) => _.isString(v) && _.isString(k))) Promise.reject('worker.envionment must be an object of string key / values only');
// }}}

// Check outputs {{{
Expand All @@ -86,9 +79,11 @@ var i3Manifest = function i3Manifest(i3) {
});
// }}}

if (errs.length) throw new Error(errs);
if (errs.length) {
i3.log(0, 'Manifest errors', errs);
Promise.reject(errs.join(', '));
}
})
.catch(e => _.castArray(e));

return manifest;
};
Expand Down

0 comments on commit f0081d7

Please sign in to comment.