Skip to content

Commit

Permalink
More explicit error on app install type mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
sblaisot authored and nono committed Oct 2, 2023
1 parent c4915ef commit 76d2ada
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions model/app/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import (

var slugReg = regexp.MustCompile(`^[a-z0-9\-]+$`)

var ErrInvalidManifestTypes = errors.New("manifest types are not the sames")
var ErrInvalidManifestTypes = errors.New("Manifest type is unknown")
var ErrInvalidManifestForWebapp = errors.New("Manifest type is not valid for a webapp. Maybe you want to install a konnector?")
var ErrInvalidManifestForKonnector = errors.New("Manifest type is not valid for a konnector. Maybe you want to install a webapp?")

// Operation is the type of operation the installer is created for.
type Operation int
Expand Down Expand Up @@ -608,7 +610,16 @@ func (i *Installer) ReadManifest(state State) (Manifest, error) {
appTypesMismatch := i.man.AppType() != newManifestAppType

if !appTypesEmpty && appTypesMismatch {
return nil, fmt.Errorf("%w: expected %d, got %d. Are you sure of %s type ? (konnector/webapp)", ErrInvalidManifestTypes, i.man.AppType(), newManifestAppType, i.man.Slug())
var typeError error
switch i.man.AppType() {
case consts.KonnectorType:
typeError = ErrInvalidManifestForKonnector
case consts.WebappType:
typeError = ErrInvalidManifestForWebapp
default:
typeError = ErrInvalidManifestTypes
}
return nil, fmt.Errorf("[%s] %w", i.man.Slug(), typeError)
}
return newManifest, nil
}
Expand Down
2 changes: 1 addition & 1 deletion model/app/installer_konnector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func TestInstallerKonnector(t *testing.T) {
assert.NoError(t, err)
_, err = inst.RunSync()
assert.Error(t, err)
assert.ErrorIs(t, err, app.ErrInvalidManifestTypes)
assert.ErrorIs(t, err, app.ErrInvalidManifestForKonnector)
})
}

Expand Down
2 changes: 1 addition & 1 deletion model/app/installer_webapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ func TestInstallerWebApp(t *testing.T) {
assert.NoError(t, err)
_, err = inst.RunSync()
assert.Error(t, err)
assert.ErrorIs(t, err, app.ErrInvalidManifestTypes)
assert.ErrorIs(t, err, app.ErrInvalidManifestForWebapp)
})
}

Expand Down

0 comments on commit 76d2ada

Please sign in to comment.