Skip to content

fail should support rethrowing an exception object #941

@krader1961

Description

@krader1961
Contributor

I noticed that this pattern fails with Exception: wrong type of 1'th argument: wrong type: need string, got exception:

try {
    /usr/bin/false
} except e {
    fail e
}

It seems to me it should be possible to re-throw an exception. Yes, you can do fail (to-string $e) but that will lose information if and when exception objects have attributes other than cause. It also violates the DRY principal (don't repeat yourself).

On a closely related note we'll probably want fail to accept options to set the hypothetical attributes that seem likely to be added in the future. As a stepping stone fail it might be useful to augment it accept an optional cause option that can be used instead of the current string argument. Either that or the current mandatory argument could be used but not both at the same time.

Activity

krader1961

krader1961 commented on Apr 9, 2020

@krader1961
ContributorAuthor

I see that @hanche proposed re-throwing an exception in this comment.

changed the title [-]`fail` should allow an exception object in addition to a string[/-] [+]`fail` should support rethrowing an exception object[/+] on May 3, 2020
modified the milestones: 0.15, 0.14 on May 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @xiaq@krader1961

        Issue actions

          `fail` should support rethrowing an exception object · Issue #941 · elves/elvish