Skip to content

Commit d1188f4

Browse files
author
Kaan Yalti
committed
enhancement(5235): added deferred error handler in upgrade function to add insufficient disk space error into the error chain
enhancement(5235): added comments for the deferred error handler in upgrade func
1 parent dcb1b3f commit d1188f4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

internal/pkg/agent/application/upgrade/upgrade.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
2424
"github.com/elastic/elastic-agent/internal/pkg/agent/application/reexec"
2525
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact"
26+
upgradeErrors "github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact/download/errors"
2627
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
2728
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
2829
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
@@ -197,6 +198,16 @@ func checkUpgrade(log *logger.Logger, currentVersion, newVersion agentVersion, m
197198
func (u *Upgrader) Upgrade(ctx context.Context, version string, sourceURI string, action *fleetapi.ActionUpgrade, det *details.Details, skipVerifyOverride bool, skipDefaultPgp bool, pgpBytes ...string) (_ reexec.ShutdownCallbackFn, err error) {
198199
u.log.Infow("Upgrading agent", "version", version, "source_uri", sourceURI)
199200

201+
defer func() {
202+
if err != nil {
203+
// Add the disk space error to the error chain if it is a disk space error
204+
// so that we can use errors.Is to check for it
205+
if upgradeErrors.IsDiskSpaceError(err) {
206+
err = goerrors.Join(err, upgradeErrors.ErrInsufficientDiskSpace)
207+
}
208+
}
209+
}()
210+
200211
currentVersion := agentVersion{
201212
version: release.Version(),
202213
snapshot: release.Snapshot(),

0 commit comments

Comments
 (0)