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

Extract detailed error information #239

Open
Turanic opened this issue Feb 20, 2021 · 2 comments · May be fixed by #273
Open

Extract detailed error information #239

Turanic opened this issue Feb 20, 2021 · 2 comments · May be fixed by #273

Comments

@Turanic
Copy link

Turanic commented Feb 20, 2021

Hi there,

I'm currently using mapstructure for an API, to convert a map[string]interface{} extracted from user inputs into a structure.
The main use-case is working very well, however I would like to generate my own error messages instead of directly using the error returned by the library.
The required information would be:

  • which field failed to be converted
  • what was the expected type
  • what was the type of the field that failed to be converted

From what I've seen, this is currently not easily done with mapstructure.
Do you think it would be possible to find those information after a call to Decode without having to scan the error message string?

@mitchellh
Copy link
Owner

I’d be open to changing the error result into a rich error type, I think that’d be the easiest way.

@Turanic
Copy link
Author

Turanic commented Feb 26, 2021

Thanks for your answer. 👍
I will be working on a PR to add some error types, corresponding to my use case.

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

Successfully merging a pull request may close this issue.

2 participants