mirror of
https://github.com/go-task/task.git
synced 2026-08-29 10:08:27 +02:00
refactor(remote): extract the fetch error translation
The same policy — keep TaskfileNotSecureError, make everything else a generic download failure — was spelled out at each of the three call sites, where copies of a security rule tend to drift apart.
This commit is contained in:
@@ -140,10 +140,7 @@ func (node *HTTPNode) ReadContext(ctx context.Context) ([]byte, error) {
|
||||
if ctx.Err() != nil {
|
||||
return nil, err
|
||||
}
|
||||
if notSecure, ok := errors.AsType[*errors.TaskfileNotSecureError](err); ok {
|
||||
return nil, notSecure
|
||||
}
|
||||
return nil, errors.TaskfileFetchFailedError{URI: node.Location()}
|
||||
return nil, taskfileFetchError(err, node.Location())
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
|
||||
@@ -51,10 +51,7 @@ func RemoteExists(ctx context.Context, u url.URL, client *http.Client) (*url.URL
|
||||
if ctx.Err() != nil {
|
||||
return nil, fmt.Errorf("checking remote file: %w", ctx.Err())
|
||||
}
|
||||
if notSecure, ok := errors.AsType[*errors.TaskfileNotSecureError](err); ok {
|
||||
return nil, notSecure
|
||||
}
|
||||
return nil, errors.TaskfileFetchFailedError{URI: u.Redacted()}
|
||||
return nil, taskfileFetchError(err, u.Redacted())
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
@@ -83,10 +80,7 @@ func RemoteExists(ctx context.Context, u url.URL, client *http.Client) (*url.URL
|
||||
// Try the alternative URL
|
||||
resp, err = client.Do(req)
|
||||
if err != nil {
|
||||
if notSecure, ok := errors.AsType[*errors.TaskfileNotSecureError](err); ok {
|
||||
return nil, notSecure
|
||||
}
|
||||
return nil, errors.TaskfileFetchFailedError{URI: u.Redacted()}
|
||||
return nil, taskfileFetchError(err, u.Redacted())
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
@@ -98,3 +92,12 @@ func RemoteExists(ctx context.Context, u url.URL, client *http.Client) (*url.URL
|
||||
|
||||
return nil, errors.TaskfileNotFoundError{URI: u.Redacted(), Walk: false}
|
||||
}
|
||||
|
||||
// taskfileFetchError preserves redirect-policy errors wrapped by http.Client.
|
||||
// Other transport errors remain generic download failures.
|
||||
func taskfileFetchError(err error, uri string) error {
|
||||
if notSecure, ok := errors.AsType[*errors.TaskfileNotSecureError](err); ok {
|
||||
return notSecure
|
||||
}
|
||||
return errors.TaskfileFetchFailedError{URI: uri}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user