0

A call like this can fail silently:

await update(ref, {...properties})

Even though this is a promise, using then/catch doesn't catch the error. If you wrap the entire thing in try/catch, you can see the error:

try{
  await update(ref, {...properties})
} catch (error) {
console.log(error)
}

console:

Error: update failed: values argument contains undefined in property...

Since this was maddening, I wanted to share the answer.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
IndieJune
  • 148
  • 7

1 Answers1

1

To solve it, wrap the properties in a function like this (adapted from Remove blank attributes from an Object in Javascript)

function removeUndefinedValues(obj: any): any {
  return Object.entries(obj)
    .filter(([_, v]) => v !== undefined)
    .reduce((acc, [k, v]) => ({ ...acc, [k]: v === Object(v) ? removeUndefinedValues(v) : v }), {});
}

await update(ref, removeUndefinedValues({...properties}))

Poof, no more silent failure

IndieJune
  • 148
  • 7