Skip to content

std.mergePatch can't merge over error values #414

@benley

Description

@benley

I was hoping that this would work:

std.mergePatch(
  { a: error "nope" },
  { a: "ok" }
)

but unfortunately that results in a runtime error, because mergePatch has to check the type of each field, and std.type(error "err") is also a runtime error.

I think it would be possible to make the above example work by checking the type of the replacement value before considering the original value, and ignoring the original value unless the replacement is an object. But it still wouldn't be possible to do this:

std.mergePatch(
  { a: error "nope" },
  { a: { b: "ok" } }
)

So now I'm wondering: Would it break the world to make std.type(error "nope") return "error" instead of an error? Or as an alternative, what about adding a boolean stdlib function like std.isError(x)?

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