fix(mixins/Tasks): correctly serialize errors

This commit is contained in:
Julien Fontanet
2023-05-17 11:29:28 +02:00
parent 2459f46c19
commit 684282f0a4
2 changed files with 16 additions and 0 deletions

View File

@@ -14,6 +14,15 @@ const formatId = timestamp => timestamp.toString(36).padStart(9, '0')
const noop = Function.prototype
// Create a serializable object from an error.
const serializeError = error => ({
...error, // Copy enumerable properties.
code: error.code,
message: error.message,
name: error.name,
stack: error.stack,
})
export default class Tasks extends EventEmitter {
// contains consolidated logs of all live and finished tasks
#store
@@ -27,6 +36,12 @@ export default class Tasks extends EventEmitter {
this.#tasks.delete(id)
},
onTaskUpdate: async taskLog => {
// Error objects are not JSON-ifiable by default
const { result } = taskLog
if (result instanceof Error && result.toJSON === undefined) {
taskLog.result = serializeError(result)
}
try {
const { $root } = taskLog

View File

@@ -32,6 +32,7 @@
<!--packages-start-->
- @xen-orchestra/mixins patch
- xo-cli minor
- xo-web minor