Skip to content

Commit

Permalink
#201 Report lack of disk space more nicely
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-andruszkiewicz-wttech committed Nov 15, 2023
1 parent c100722 commit 70020ea
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (pm *PackageManager) uploadOptimized(localPath string) (string, error) {
return "", fmt.Errorf("%s > cannot upload package '%s'; cannot parse response: %w", pm.instance.ID(), localPath, err)
}
if !status.Success {
return "", fmt.Errorf("%s > cannot upload package '%s'; unexpected status: %s", pm.instance.ID(), localPath, status.Message)
return "", fmt.Errorf("%s > cannot upload package '%s'; %s", pm.instance.ID(), localPath, pm.interpretFail(status.Message))
}
log.Infof("%s > uploaded package '%s'", pm.instance.ID(), localPath)
return status.Path, nil
Expand All @@ -423,12 +423,19 @@ func (pm *PackageManager) uploadBuffered(localPath string) (string, error) {
return "", fmt.Errorf("%s > cannot upload package '%s'; cannot parse response: %w", pm.instance.ID(), localPath, err)
}
if !status.Success {
return "", fmt.Errorf("%s > cannot upload package '%s'; unexpected status: %s", pm.instance.ID(), localPath, status.Message)
return "", fmt.Errorf("%s > cannot upload package '%s'; %s", pm.instance.ID(), localPath, pm.interpretFail(status.Message))
}
log.Infof("%s > uploaded package '%s'", pm.instance.ID(), localPath)
return status.Path, nil
}

func (pm *PackageManager) interpretFail(message string) string {
if strings.EqualFold(message, "Inaccessible value") {
return fmt.Sprintf("probably no disk space left (server respond with '%s')", message) // https://forums.adobe.com/thread/2338290
}
return fmt.Sprintf("unexpected status: %s", message)
}

func (pm *PackageManager) Install(remotePath string) error {
if pm.InstallHTMLEnabled {
return pm.installHTML(remotePath)
Expand Down
51 changes: 51 additions & 0 deletions pkg/package_manager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package pkg

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestPackageManager_interpretFail(t *testing.T) {
type fields struct {
instance *Instance
UploadOptimized bool
InstallRecursive bool
InstallHTMLEnabled bool
InstallHTMLConsole bool
InstallHTMLStrict bool
SnapshotDeploySkipping bool
SnapshotIgnored bool
SnapshotPatterns []string
ToggledWorkflows []string
}
type args struct {
message string
}
tests := []struct {
name string
fields fields
args args
want string
}{
{"no message", fields{}, args{}, "unexpected status: "},
{"generic message", fields{}, args{"generic message"}, "unexpected status: generic message"},
{"inaccessible value", fields{}, args{"Inaccessible value"}, "probably no disk space left (server respond with 'Inaccessible value')"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pm := &PackageManager{
instance: tt.fields.instance,
UploadOptimized: tt.fields.UploadOptimized,
InstallRecursive: tt.fields.InstallRecursive,
InstallHTMLEnabled: tt.fields.InstallHTMLEnabled,
InstallHTMLConsole: tt.fields.InstallHTMLConsole,
InstallHTMLStrict: tt.fields.InstallHTMLStrict,
SnapshotDeploySkipping: tt.fields.SnapshotDeploySkipping,
SnapshotIgnored: tt.fields.SnapshotIgnored,
SnapshotPatterns: tt.fields.SnapshotPatterns,
ToggledWorkflows: tt.fields.ToggledWorkflows,
}
assert.Equalf(t, tt.want, pm.interpretFail(tt.args.message), "interpretFail(%v)", tt.args.message)
})
}
}

0 comments on commit 70020ea

Please sign in to comment.