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

Error handling is bogus #21

@gabyx

Description

@gabyx

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions