Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How about adding more clear error message for some builtin functions? #867

Open
0x005c opened this issue Oct 29, 2019 · 1 comment
Open

How about adding more clear error message for some builtin functions? #867

0x005c opened this issue Oct 29, 2019 · 1 comment

Comments

@0x005c
Copy link
Contributor

@0x005c 0x005c commented Oct 29, 2019

Now, % and randint just throw args error; it is difficult to understand why the function failed.

~/go/src/github.com/elves/elvish> % 2 0
Exception: args error
[tty], line 1: % 2 0
~/go/src/github.com/elves/elvish> randint 100 0
Exception: args error
[tty], line 1: randint 100 0

How about adding better error messages for them?

@xiaq

This comment has been minimized.

Copy link
Member

@xiaq xiaq commented Oct 29, 2019

Yes! I would like to have such errors be structured too, like:

type SingleArgError struct {
    Which int
    Want string
    Got string
}

func (err SingleArgError) Error() string {
    return fmt.Sprintf(
        "error with argument #%d: want %s, got %s", err.Which, err.Want, err.Got)
}

Although Want and Got are now strings, in future they can potentially be structured too, as some kind of representation of types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.