dlgs icon indicating copy to clipboard operation
dlgs copied to clipboard

Error handling is bogus

Open gabyx opened this issue 4 years ago • 0 comments

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.

gabyx avatar Feb 10 '21 22:02 gabyx