Skip to content

Commit

Permalink
machines: Don't swallow promise failures
Browse files Browse the repository at this point in the history
This makes it possible to use the promises returned by the asynchronous
actions.

Closes #7121
This uses 'fail' instead of 'catch'.  Also, it intercepts the
getVirtProvider errors only and not errors from the actual method call
as well.
  • Loading branch information
mvollmer authored and martinpitt committed Jun 28, 2017
1 parent f0ffc99 commit 1e6dd9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/machines/libvirt.es6
Expand Up @@ -265,7 +265,7 @@ function spawnVirsh({connectionName, method, failHandler, args}) {
cmd: 'virsh',
args: VMS_CONFIG.Virsh.connections[connectionName].params.concat(args),
failHandler,
}).catch((ex, data, output) => {
}).fail((ex, data, output) => {
const msg = `${method}() exception: '${ex}', data: '${data}', output: '${output}'`;
if (failHandler) {
logDebug(msg);
Expand Down
10 changes: 6 additions & 4 deletions pkg/machines/provider.es6
Expand Up @@ -111,15 +111,17 @@ function getVirtProvider (store) {
* Lazily initializes the virt provider and dispatches given method on it.
*/
export function virt(method, action) {
return (dispatch, getState) => getVirtProvider({dispatch, getState}).then(provider => {
return (dispatch, getState) => getVirtProvider({dispatch, getState}).fail(err => {
console.error('could not detect any virt provider');
}).then(provider => {
if (method in provider) {
logDebug(`Calling ${provider.name}.${method}`, action);
return dispatch(provider[method](action));
} else {
console.warn(`method: '${method}' is not supported by provider: '${provider.name}'`);
var msg = `method: '${method}' is not supported by provider: '${provider.name}'`;
console.warn(msg);
return cockpit.reject(msg);
}
}).catch(err => {
console.error('could not detect any virt provider');
});
}

Expand Down

0 comments on commit 1e6dd9f

Please sign in to comment.