AlecAivazis / survey

A golang library for building interactive and accessible prompts with full support for windows and posix terminals.
MIT License
4.08k stars 351 forks source link

Add core.IsFieldNotMatch function. #263

Closed kataras closed 4 years ago

kataras commented 4 years ago

Hello @AlecAivazis,

I am pushing this PR in order to check if an error is caused of an unmatched field. There are cases when a map can be ignored (e.g. when you have a Transform which stores a value to a non-string type , take for example a map[string]interface{} from file path(input), as it can't just returned as other type because input.go#101 will panic).

import "ithub.com/AlecAivazis/survey/v2"
import "ithub.com/AlecAivazis/survey/v2/core"

// [...]

err := survey.Ask(qs, &v);
if err != nil {
  if name, ok := core.IsFieldNotMatch(err); ok {
    // [...name is the not matched question name]
  }
}

Please accept this PR as soon as possible, it

Happy Holidays!

AlecAivazis commented 4 years ago

Hey @kataras! Happy holidays to you aswell.

I think this is a fine addition to survey/core. Mind adding some tests for the new logic?

kataras commented 4 years ago

Hey @kataras! Happy holidays to you aswell.

I think this is a fine addition to survey/core. Mind adding some tests for the new logic?

There is no change on the logic. Just a typed error instead of a string-based error.

AlecAivazis commented 4 years ago

@kataras there is in fact new logic. func (err errFieldNotMatch) Is(target error) and IsFieldNotMatch are both new functions/methods. I would like to maintain as good coverage as I can and both of these are very easily testable

AlecAivazis commented 4 years ago

@kataras - I'm a bit surprised by your response. I hoped that the responsibility act includes test coverage and actually seeing a PR through

I'm going to merge this but you clearly did not read the contribution guidelines and have little intention of adding tests to cover the new logic. Please understand that i have to maintain your contribution and tests help me do that.