Errors, documentation.

This commit is contained in:
Nuno Cruces 2022-07-28 00:11:12 +01:00
parent 7ac67006b5
commit 60a828af0a
4 changed files with 17 additions and 6 deletions

View file

@ -5,6 +5,7 @@ package zenutil
import (
"bytes"
"context"
"fmt"
"io"
"os"
"os/exec"
@ -77,11 +78,14 @@ func (d *progressDialog) wait(extra *string, out *bytes.Buffer) {
case eerr.ExitCode() == -1 && atomic.LoadInt32(&d.closed) != 0:
err = nil
case eerr.ExitCode() == 1:
if extra != nil && *extra+"\n" == string(out.Bytes()) {
out := bytes.TrimSuffix(out.Bytes(), []byte{'\n'})
if extra != nil && *extra == string(out) {
err = ErrExtraButton
} else {
err = ErrCanceled
}
default:
err = fmt.Errorf("%w: %s", eerr, eerr.Stderr)
}
}
d.err = err

View file

@ -13,6 +13,9 @@ func list(text string, items []string, opts options) (string, error) {
if opts.extraButton != nil {
return "", fmt.Errorf("%w: extra button", ErrUnsupported)
}
if len(opts.defaultItems) > 1 {
return "", fmt.Errorf("%w: multiple default items", ErrUnsupported)
}
var data zenutil.List
data.Items = items

2
pwd.go
View file

@ -10,7 +10,7 @@ func Password(options ...Option) (usr string, pwd string, err error) {
return password(applyOptions(options))
}
// Username returns an Option to display the username (Unix only).
// Username returns an Option to display the username.
func Username() Option {
return funcOption(func(o *options) { o.username = true })
}

View file

@ -4,6 +4,7 @@ package zenity
import (
"bytes"
"fmt"
"os/exec"
"strconv"
"strings"
@ -66,11 +67,14 @@ func appendWindowIcon(args []string, opts options) []string {
func strResult(opts options, out []byte, err error) (string, error) {
out = bytes.TrimSuffix(out, []byte{'\n'})
if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 {
if opts.extraButton != nil && *opts.extraButton == string(out) {
return "", ErrExtraButton
if eerr, ok := err.(*exec.ExitError); ok {
if eerr.ExitCode() == 1 {
if opts.extraButton != nil && *opts.extraButton == string(out) {
return "", ErrExtraButton
}
return "", ErrCanceled
}
return "", ErrCanceled
return "", fmt.Errorf("%w: %s", eerr, eerr.Stderr)
}
if err != nil {
return "", err