Compare commits

..

1 Commits

Author SHA1 Message Date
DaneEveritt
ac81409505 clearer error messaging on downloads, don't log as a 500-level error 2026-04-01 17:25:18 -07:00
4 changed files with 34 additions and 11 deletions

4
go.mod
View File

@@ -13,7 +13,7 @@ require (
github.com/apex/log v1.9.0
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
github.com/beevik/etree v1.5.0
github.com/buger/jsonparser v1.1.2
github.com/buger/jsonparser v1.1.1
github.com/cenkalti/backoff/v4 v4.3.0
github.com/creasty/defaults v1.8.0
github.com/docker/docker v28.3.3+incompatible
@@ -45,7 +45,6 @@ require (
golang.org/x/crypto v0.46.0
golang.org/x/sync v0.19.0
golang.org/x/sys v0.39.0
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
@@ -133,6 +132,7 @@ require (
golang.org/x/net v0.47.0 // indirect
golang.org/x/term v0.38.0 // indirect
golang.org/x/text v0.32.0 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
google.golang.org/protobuf v1.36.5 // indirect
gotest.tools/v3 v3.0.2 // indirect

4
go.sum
View File

@@ -57,8 +57,8 @@ github.com/bodgit/sevenzip v1.6.1 h1:kikg2pUMYC9ljU7W9SaqHXhym5HyKm8/M/jd31fYan4
github.com/bodgit/sevenzip v1.6.1/go.mod h1:GVoYQbEVbOGT8n2pfqCIMRUaRjQ8F9oSqoBEqZh5fQ8=
github.com/bodgit/windows v1.0.1 h1:tF7K6KOluPYygXa3Z2594zxlkbKPAOvqr97etrGNIz4=
github.com/bodgit/windows v1.0.1/go.mod h1:a6JLwrB4KrTR5hBpp8FI9/9W9jJfeQ2h4XDXU74ZCdM=
github.com/buger/jsonparser v1.1.2 h1:frqHqw7otoVbk5M8LlE/L7HTnIq2v9RX6EJ48i9AxJk=
github.com/buger/jsonparser v1.1.2/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/bytedance/sonic v1.13.1 h1:Jyd5CIvdFnkOWuKXr+wm4Nyk2h0yAFsr8ucJgEasO3g=
github.com/bytedance/sonic v1.13.1/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=

View File

@@ -25,6 +25,7 @@ var client *http.Client
func init() {
dialer := &net.Dialer{
LocalAddr: nil,
Timeout: time.Second * 30,
}
trnspt := http.DefaultTransport.(*http.Transport).Clone()
@@ -55,10 +56,8 @@ func init() {
}
client = &http.Client{
Timeout: time.Hour * 12,
Timeout: time.Hour * 2,
Transport: trnspt,
// Disallow any redirect on an HTTP call. This is a security requirement: do not modify
// this logic without first ensuring that the new target location IS NOT within the current
// instance's local network.
@@ -192,7 +191,10 @@ func (dl *Download) Execute() error {
req.Header.Set("User-Agent", "Pterodactyl Panel (https://pterodactyl.io)")
res, err := client.Do(req)
if err != nil {
return ErrDownloadFailed
if IsDownloadError(err) {
return err
}
return errors.Wrap(err, ErrDownloadFailed.Error())
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
@@ -335,3 +337,7 @@ func mustParseCIDR(ip string) *net.IPNet {
}
return block
}
func IsDownloadError(err error) bool {
return errors.Is(err, ErrDownloadFailed) || errors.Is(err, ErrInvalidIPAddress) || errors.Is(err, ErrInternalResolution)
}

View File

@@ -328,13 +328,15 @@ func postServerPullRemoteFile(c *gin.Context) {
download := func() error {
s.Log().WithField("download_id", dl.Identifier).WithField("url", u.String()).Info("starting pull of remote file to disk")
if err := dl.Execute(); err != nil {
s.Log().WithField("download_id", dl.Identifier).WithField("error", err).Error("failed to pull remote file")
if !downloader.IsDownloadError(err) {
s.Log().WithField("download_id", dl.Identifier).WithField("error", err).Error("failed to pull remote file")
}
return err
} else {
s.Log().WithField("download_id", dl.Identifier).Info("completed pull of remote file")
}
s.Log().WithField("download_id", dl.Identifier).Info("completed pull of remote file")
return nil
}
if !data.Foreground {
go func() {
_ = download()
@@ -346,6 +348,21 @@ func postServerPullRemoteFile(c *gin.Context) {
}
if err := download(); err != nil {
if downloader.IsDownloadError(err) {
var message = "The URL or IP address provided could not be resolved to a valid destination."
if errors.Is(err, downloader.ErrDownloadFailed) {
s.Log().WithField("identifier", dl.Identifier).WithField("error", err).Warn("failed to download remote file")
message = "An error was encountered while trying to download this file. Please try again later."
}
c.JSON(http.StatusBadRequest, gin.H{
"identifier": dl.Identifier,
"message": message,
})
return
}
middleware.CaptureAndAbort(c, err)
return
}