in src/agentmgr.js [101:145]
async peekAction() {
let action = await getWskActionWithoutCode(this.wsk, this.actionName);
if (action === null) {
throw new Error(`Action not found: ${this.actionName}`);
}
// check if there was an agent leftover
if (isAgent(action)) {
// ups, action is our agent, not the original
// happens if a previous wskdebug was killed and could not restore before it exited
const backupName = getActionCopyName(this.actionName);
// check the backup action
try {
const backup = await getWskActionWithoutCode(this.wsk, backupName);
if (!backup) {
// backup is also an agent (should not happen)
throw new Error(`Dang! Agent is already installed and action backup is missing.\n\nPlease redeploy your action first before running wskdebug again.`);
} else if (isAgent(backup)) {
// backup is also an agent (should not happen)
throw new Error(`Dang! Agent is already installed and action backup is broken (${backupName}).\n\nPlease redeploy your action first before running wskdebug again.`);
} else {
log.warn("Agent was already installed, but backup is still present. All good.");
// need to look at the original action
action = backup;
this.agentInstalled = true;
}
} catch (e) {
if (e.statusCode === 404) {
// backup missing
throw new Error(`Dang! Agent is already installed and action backup is gone (${backupName}).\n\nPlease redeploy your action first before running wskdebug again.`);
} else {
// other error
throw e;
}
}
}
return action;
}