Can you show what is output by this line before both types of errors?
log(`Adding operation to upsert ${result.type} with value ${result.value}`);
There might be more information from the errors if you remove the try/catch and let the frame work display the errors.