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

Improve error message for custom capture #254

Open
sievlev opened this issue Jul 29, 2022 · 2 comments
Open

Improve error message for custom capture #254

sievlev opened this issue Jul 29, 2022 · 2 comments

Comments

@sievlev
Copy link

sievlev commented Jul 29, 2022

If custom capture generate an error, then user will receive an error message with full struct name.

 diff --git a/_examples/ini/main.go b/_examples/ini/main.go
 index be6ec9e..e483923 100644
 --- a/_examples/ini/main.go
 +++ b/_examples/ini/main.go
 @@ -1,6 +1,7 @@
  package main
  
  import (
 +       "errors"
         "os"
  
         "github.com/alecthomas/repr"
 @@ -51,11 +52,17 @@ type String struct {
  func (String) value() {}
  
  type Number struct {
 -       Number float64 `@Float`
 +       Number N `@Float`
  }
  
  func (Number) value() {}
  
 +type N struct{}
 +
 +func (*N) Capture(values []string) error {
 +       return errors.New("problem")
 +}
 +

panic: Number.Number: problem

An error message with type name or token name will be much better:
<float>: problem

@alecthomas
Copy link
Owner

Mmm yeah, that's not ideal and doesn't match the rest of the error reporting.

@sievlev
Copy link
Author

sievlev commented Aug 25, 2022

It's not a good idea to expose internal details to external users when this library is used for some sort of service. At least the library should provide a way to customize error messages.

See also #253 - an attempt to resurrect v1 behaviour on other place.

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

No branches or pull requests

2 participants