8000 Improve MatchError message · Issue #493 · evhub/coconut · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Improve MatchError message #493
Closed
Closed
@arnauorriols

Description

@arnauorriols

After using Coconut for some production projects now, one of the main issues we face is that many times the MatchError messages are not usable in practice, and sometimes they really get in the way.

The main case when this happens is when the parameters of the function (when using Pattern-matching functions) are very big datastructures. Here's an example:

>>> def foo(x is int, y is list):
      pass
>>> foo(4.5, ["foo"] * 1000000)
# result: screen full of hypnotizing "foo"s. Try it to get the idea 

In these cases, the current behavior not only slows down debugging or makes it impossible in practice, it also harms the perception of quality that our clients get.

The easiest solution would be to truncate the output when it exceeds a (high) safe threshold. However, this would solve only part of the problem. It could be that the match error was indeed inside the truncated part of the message. The ideal solution would be to improve the messages so that they are capable of narrowing down the point of failure as much as possible. Something on the lines of:

>>> def foo(x is int, y is list):
      pass
>>> foo(4.5, ["foo"] * 1000000)
coconut.__coconut__.MatchError: pattern-matching failed 
    for 'def foo(x is int, y is list):'
    in "(4.5, ['foo', 'foo', 'foo', 'foo', 'foo', 'foo', 'foo', 'foo', ... 'foo'])"

    expected: x is int
    received: 4.5

I'm probably missing some use cases that collide with this proposal, but I hope a middle ground can be found that benefits everybody :) What do you think?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0