Skip to content
This repository has been archived by the owner on Jun 3, 2022. It is now read-only.

Error handling is bogus #21

Open
gabyx opened this issue Feb 10, 2021 · 0 comments
Open

Error handling is bogus #21

gabyx opened this issue Feb 10, 2021 · 0 comments

Comments

@gabyx
Copy link
Contributor

gabyx commented Feb 10, 2021

Thanks for this library, its helpful!

However there is some caveat regarding error handling and "cancel/close dialog" actions:
I am not quite sure for what the boolean return value should have been.

The logic right now on Linux:

func Entry(title, text, defaultText string) (string, bool, error)
	o, err := exec.Command(cmd, "--entry", "--title", title, "--text", text, "--entry-text", defaultText).Output()
	if err != nil {
		if exitError, ok := err.(*exec.ExitError); ok {
			ws := exitError.Sys().(syscall.WaitStatus)
			return "", ws.ExitStatus() == 0, nil  // <<<<<< Correct reporting a Cancle OR Close action
		}
	}

	ret := true
	out := strings.TrimSpace(string(o))
	if out == "" {
		ret = false // <<<<<<<<<<<< Why is an empty answer unsuccesful. (1)
	}

	return out, ret, err
}

Removing the check for the empty string at the end, would be desirable, since validation of the string should strongly be done outside of this function.
Doing this, gives the boolean value the meaning

  • true : if the User has pressed OK and accepts the entry.
  • false : the user has closed or cancled.
  • Any returned error is a exec Error...

With the current logic, we cannot properly distinguish between this.

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

No branches or pull requests

1 participant