Skip to content

PersistentPostRunE isn't executed if the command fails #914

@Skarlso

Description

@Skarlso

What happened:

I added a debug statement:

	previouspostRunE := cmd.PersistentPostRunE
	cmd.PersistentPostRunE = func(cmd *cobra.Command, args []string) error {
		fmt.Println("Shutting down plugin manager after exit")
		var err error
		if previouspostRunE != nil {
			err = previouspostRunE(cmd, args)
		}
		ctx, cancel := context.WithTimeout(cmd.Context(), 10*time.Second)
		defer cancel()
		return errors.Join(err, pluginManager.Shutdown(ctx))
	}

And if the command run successfully, it appeared and shutdown the plugin manager.

If I ran the command that quit with an error ( like parsing a reference or the component already exist error ) this post run wasn't executed and the plugin manager did not shut down properly.

What you expected to happen:

The post run hook to actually execute regardless of the outcome of the command.

How to reproduce it (as minimally and precisely as possible):

Run add cv with something that fails but gets to actually run a plugin so the plugin starts up. Here is a sample component constructor:

components:
- name: ocm.software/test-component-helm
  version: 1.0.0
  provider:
    name: acme.org
  resources:
    - name: helm-chart
      version: 1.0.0
      type: helmChart
      input:
        type: helm/v1
        helmRepository: https://stefanprodan.github.io/podinfo/podinfo-6.9.1.tgz
ocm add component-version --repository ghcr.io/<your-user>/test-signed-helmchart --constructor component-constructor.yaml --loglevel debug

Anything else we need to know:

Environment:

Metadata

Metadata

Assignees

Labels

area/ipceiImportant Project of Common European Interestkind/bugfixBug

Type

No fields configured for Bug.

Projects

Status
🍺 Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions