Skip to content

Commit

Permalink
Merge pull request #596 from eco-stake/autostake-handle-early-failure
Browse files Browse the repository at this point in the history
Handle early autostake failure correctly
  • Loading branch information
tombeynon authored Sep 13, 2022
2 parents bbd880f + 84a375d commit 87d4fdd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/autostake/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function Autostake(mnemonic, opts) {
logSummary(health, result)
})
}
if (lastResult?.didSucceed() || (!lastResult && results)) {
if (lastResult?.didSucceed() || results === true) {
return health.success('Autostake finished')
} else {
return health.failed('Autostake failed')
Expand Down Expand Up @@ -77,7 +77,7 @@ export default function Autostake(mnemonic, opts) {
} catch (e) {
error = e.message
}
if (retries < maxRetries && !networkRunner.forceFail) {
if (retries < maxRetries && !networkRunner?.forceFail) {
await logResults(health, networkRunner, error, `Failed attempt ${retries + 1}/${maxRetries + 1}, retrying in 30 seconds...`)
await new Promise(r => setTimeout(r, 30 * 1000));
return await runWithRetry(data, health, retries + 1, runners)
Expand All @@ -87,8 +87,10 @@ export default function Autostake(mnemonic, opts) {
}

function logResults(health, networkRunner, error, message) {
health.addLogs(networkRunner.queryErrors())
logSummary(health, networkRunner)
if(networkRunner){
health.addLogs(networkRunner.queryErrors())
logSummary(health, networkRunner)
}
if (error) health.log(`Failed with error: ${error}`)
if (message) health.log(message)
return health.sendLog()
Expand Down

0 comments on commit 87d4fdd

Please sign in to comment.