Skip to content

Commit

Permalink
fix(installer): Fix reporting of error code
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteFoy committed Dec 11, 2024
1 parent 6b70b84 commit 4b383ea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pkg/fleet/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,10 @@ func (d *daemonImpl) handleRemoteAPIRequest(request remoteAPIRequest) (err error
}
experimentPackage, ok := d.catalog.getPackage(request.Package, params.Version, runtime.GOARCH, runtime.GOOS)
if !ok {
return fmt.Errorf("could not get package %s, %s for %s, %s", request.Package, params.Version, runtime.GOARCH, runtime.GOOS)
return installerErrors.Wrap(
installerErrors.ErrPackageNotFound,
fmt.Errorf("could not get package %s, %s for %s, %s", request.Package, params.Version, runtime.GOARCH, runtime.GOOS),
)
}
log.Infof("Installer: Received remote request %s to start experiment for package %s version %s", request.ID, request.Package, request.Params)
if request.Package == "datadog-installer" {
Expand Down
6 changes: 3 additions & 3 deletions pkg/fleet/installer/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ func (e InstallerError) ToJSON() string {
}

// FromJSON returns an InstallerError from a JSON string.
func FromJSON(errStr string) InstallerError {
func FromJSON(errStr string) *InstallerError {
var jsonError installerErrorJSON
err := json.Unmarshal([]byte(errStr), &jsonError)
if err != nil {
return InstallerError{
return &InstallerError{
err: errors.New(errStr),
code: errUnknown,
}
}
return InstallerError{
return &InstallerError{
err: errors.New(jsonError.Error),
code: InstallerErrorCode(jsonError.Code),
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fleet/internal/exec/installer_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,5 @@ func (iCmd *installerCmd) Run() error {
}

installerError := installerErrors.FromJSON(strings.TrimSpace(errBuf.String()))
return fmt.Errorf("run failed: %v \n%s", installerError, err.Error())
return fmt.Errorf("run failed: %w \n%s", installerError, err.Error())
}

0 comments on commit 4b383ea

Please sign in to comment.