Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants