From 76d2ada9c7264e86f3cb0d4d7a39d330d9e1988b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blaisot?= Date: Fri, 29 Sep 2023 14:33:34 +0200 Subject: [PATCH] More explicit error on app install type mismatch --- model/app/installer.go | 15 +++++++++++++-- model/app/installer_konnector_test.go | 2 +- model/app/installer_webapp_test.go | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/model/app/installer.go b/model/app/installer.go index 9d3b867cbbd..4ca886b10ed 100644 --- a/model/app/installer.go +++ b/model/app/installer.go @@ -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 @@ -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 } diff --git a/model/app/installer_konnector_test.go b/model/app/installer_konnector_test.go index 05f95375c9a..c4a37ced73e 100644 --- a/model/app/installer_konnector_test.go +++ b/model/app/installer_konnector_test.go @@ -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) }) } diff --git a/model/app/installer_webapp_test.go b/model/app/installer_webapp_test.go index 8a2bee30bb9..4747bff4e97 100644 --- a/model/app/installer_webapp_test.go +++ b/model/app/installer_webapp_test.go @@ -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) }) }