Skip to content

Commit

Permalink
fix the absence of circular structure treatment
Browse files Browse the repository at this point in the history
  • Loading branch information
vxksf committed Aug 18, 2021
1 parent 39d9b16 commit 09985c4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/step.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,32 @@ class Step {
return Ok(ret)
}

let circularStructureCache = []
const _circularStructureHandling = (key, value) => {
if (typeof value === 'object' && value !== null) {
if (circularStructureCache.includes(value)) return
circularStructureCache.push(value)
}
return value
}

let ret = undefined
this._auditTrail.description = this.description
this._auditTrail.return = ""

ret = await _runFunction()
if (ret !== undefined) this._auditTrail.return = JSON.parse(JSON.stringify(ret))
if (ret !== undefined) {
this._auditTrail.return = JSON.parse(JSON.stringify(ret, _circularStructureHandling))
circularStructureCache = []
}

if (ret) {
this._auditTrail.elapsedTime = process.hrtime.bigint() - startTime
return ret
}

ret = await _runNestedSteps()
this._auditTrail.return = JSON.parse(JSON.stringify(ret))
this._auditTrail.return = JSON.parse(JSON.stringify(ret, _circularStructureHandling))
this._auditTrail.elapsedTime = process.hrtime.bigint() - startTime
return ret
}
Expand Down

0 comments on commit 09985c4

Please sign in to comment.