Skip to content

Question on ResultObject design #80

@headlessme

Description

@headlessme

Is there a reason to return a structured object that contains an error / value property instead of using the more standard resolved / rejected promise that works with normal JS error handling flows? Are the Promises you're returning guaranteed to never throw an error?

I'm finding it makes it easy to miss error handling as it not the standard try / catch usually seen with async functions.

The design seems to be forcing a lot of duplicate handling of errors, e.g.:

try {
  const result = await storage.addFileFromBuffer(...)
  if (result.error) handleErrors(result.error)
  else doSomethingElse(result.value)
} catch (err) {
  handleError(err)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions