Accessing resource block error when called from javascript block

If I were using a resource block, with “continue on error”, and an error occurred, I would have some error information available in a downstream javascript block. How can I get that same error information, when using a single-step resource function, called from javascript?

If wired up as above,

callGetCaseWrapper.error will be

{
  error: 'Error: \n' +"WHERE Id = 'abc123'\n" +'      ^\n' +'ERROR at Row:3:Column:7\n' +'invalid ID field: abc123 (line 1)',
  data: null,
  value: null,
  metadata: null,
  loggingMetadata: undefined
}

if callGetCaseWrapper is wired up directly to getCase, code1 will log the full error object I would expected

callGetCaseWrapper.error will be

{
  statusCode: 400,
  error: 'Bad Request',
  message: '\n' +"WHERE Id = 'abc123'\n" +'      ^\n' +'ERROR at Row:3:Column:7\n' +'invalid ID field: abc123',
  data: null
}

To be explicit, I am asking for 2 things here.

  1. callGetCaseWrapper calls getCaseWrapper which in turn calls getCaseWrapper. As the screenshot above shows, there is no try/catch around the call to getCase. Therefore, the exception that is effectively raised by getCase should be passed through, and not mangled with.
  2. If I were to modify getCaseWrapper and wrap getCase in a try/catch, when an error occurs, I would like to gain access to the same error as if getCase were called outside of javascript.

And then, a big :cherries: on top – it would be outstanding if I could establish the shape of the error object from a javascript block. Example below.

const myError = new Error("Something is messed up.");
myError.statusCode: 422;
myError.error = 'You provided an invalid value for xyz';
myError.message = 'blah';
raise myError;

It’s probably worth calling out, since it is inconsistent – if callGetCaseWrapper were “exit on error”, the global error handler would in fact have workflowContext.currentRun.errorDetails populated with:

{
  statusCode: 400,
  error: 'Bad Request',
  message: '\n' +"WHERE Id = 'abc123'\n" +'      ^\n' +'ERROR at Row:3:Column:7\n' +'invalid ID field: abc123',
  data: null
}

This is the exact behavior I’d expect with “continue on error”, albeit not in global error handler.

UPDATE: I might have underestimated this, but am still digging into it. To your last point, though, you can technically pass as much context as you want when throwing an error if you construct an object, serialize it, and set it as the error message.


Hey @lkiss - thanks for reaching out. More than anything, this looks like an inherent limitation to the way JS blocks handle errors. They essentially strip all metadata from the resulting `Error` object and simply construct an error string from `myError.message`:

I'll document this internally and start looking into possible workarounds! As soon as there is news to share, I'll reach out here. :+1: