Skip to content

Commit f585ac8

Browse files
committed
fixed error handling and messeges
1 parent 83d7e56 commit f585ac8

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

option.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Options struct {
1414
Help bool `short:"h" long:"help"`
1515
Procs int `short:"p" long:"procs"`
1616
Output string `short:"o" long:"output"`
17-
Timeout int `short:"t" long:"timeout"`
17+
Timeout int `short:"t" long:"timeout" default:"10"`
1818
UserAgent string `short:"u" long:"user-agent"`
1919
Referer string `short:"r" long:"referer"`
2020
Update bool `long:"check-update"`
@@ -43,7 +43,7 @@ func (opts Options) usage(version string) []byte {
4343
-h, --help print usage and exit
4444
-p, --procs <num> split ratio to download file
4545
-o, --output <filename> output file to <filename>
46-
-t, --timeout <seconds> timeout of checking request in seconds
46+
-t, --timeout <seconds> timeout of checking request in seconds (default 10s)
4747
-u, --user-agent <agent> identify as <agent>
4848
-r, --referer <referer> identify as <referer>
4949
--check-update check if there is update available

pget.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (pget *Pget) parseURLs() error {
166166

167167
if len(pget.URLs) < 1 {
168168
fmt.Fprintf(stdout, "Please input url separate with space or newline\n")
169-
fmt.Fprintf(stdout, "Start download at ^D\n")
169+
fmt.Fprintf(stdout, "Start download with ^D\n")
170170

171171
// scanning url from stdin
172172
scanner := bufio.NewScanner(os.Stdin)

requests.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func Check(ctx context.Context, c *CheckConfig) (*Target, error) {
4141
defer cancel()
4242

4343
if len(c.URLs) == 0 {
44-
return nil, errors.New("invalid target URL is zero")
44+
return nil, errors.New("URL is required at least one")
4545
}
4646

4747
infos, err := getMirrorInfos(ctx, c.URLs)
@@ -76,7 +76,7 @@ func getMirrorInfos(ctx context.Context, urls []string) ([]*mirrorInfo, error) {
7676
eg.Go(func() error {
7777
info, err := getMirrorInfo(ctx, url)
7878
if err != nil {
79-
return err
79+
return errors.Wrap(err, url)
8080
}
8181

8282
mu.Lock()
@@ -102,17 +102,17 @@ type mirrorInfo struct {
102102
func getMirrorInfo(ctx context.Context, url string) (*mirrorInfo, error) {
103103
req, err := http.NewRequest("HEAD", url, nil)
104104
if err != nil {
105-
return nil, errors.Wrapf(err, "failed to make head request: %q", url)
105+
return nil, errors.Wrap(err, "failed to make head request")
106106
}
107107
req = req.WithContext(ctx)
108108

109109
resp, err := http.DefaultClient.Do(req)
110110
if err != nil {
111-
return nil, errors.Wrapf(err, "failed to head request: %q", url)
111+
return nil, errors.Wrap(err, "failed to head request")
112112
}
113113

114114
if resp.Header.Get("Accept-Ranges") != "bytes" {
115-
return nil, errors.Errorf("does not support range request: %q", url)
115+
return nil, errors.New("does not support range request")
116116
}
117117

118118
if resp.ContentLength <= 0 {

0 commit comments

Comments
 (0)