Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

odo catalog list services -o json throws error when no services are available #4024

Closed
jeffmaury opened this issue Sep 23, 2020 · 5 comments · Fixed by #4148
Closed

odo catalog list services -o json throws error when no services are available #4024

jeffmaury opened this issue Sep 23, 2020 · 5 comments · Fixed by #4148
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. v2 Issue or PR that applies to the v2 of odo
Projects

Comments

@jeffmaury
Copy link
Member

/kind bug

What versions of software are you using?

Operating System:
Win10Pro

Output of odo version:

odo v2.0.0-beta-1 (c19e1f390)       
                                    
Server: https://172.23.121.200:8443 
Kubernetes: v1.11.0+d4cacc0         

How did you run odo exactly?

odo catalog list services -o json

Actual behavior

Exit code is non zero and payload is:

{                                                                                  
        "kind": "Error",                                                           
        "apiVersion": "odo.dev/v1alpha1",                                          
        "metadata": {                                                              
                "creationTimestamp": null                                          
        },                                                                         
        "message": "no deployable services/operators found"                        
}                                                                                  

Expected behavior

Should execute normally and return a payload with an empty list of items

Any logs, error output, etc?

Run against OCP3 (CDK) with only service catalog installed

@dharmit
Copy link
Member

dharmit commented Sep 24, 2020

The behaviour we're seeing here is observed in more than just one place. For example:

$ odo service list -o json         
{
	"kind": "Error",
	"apiVersion": "odo.dev/v1alpha1",
	"metadata": {
		"creationTimestamp": null
	},
	"message": "Please specify the application name and project name\nOr use the command from inside a directory containing an odo component."
}

$ echo $?
1

The behaviour can be attributed to the use of LogErrorAndExit function which exits with os.Exit(1): https://github.com/openshift/odo/blob/76f306ea5c23c64873828548a3ece33a03174241/pkg/odo/util/cmdutils.go#L56-L57

Changing the behaviour for one command and not for another would be a tough and messy task, I guess. Besides, it would lead to inconsistency and hence bad UX, IMO.

@jeffmaury under what circumstances would you, as a user, prefer exit code be 1 when executing -o json commands?

@jeffmaury
Copy link
Member Author

The rules would be the following:

  • if the execution is able to generate the expected JSON output, then exit code should be 0
  • otherwise exit code is non zero.

So I'm not complaining about the exit code but rather against the generated JSON output that should be one expected with an empty list

@girishramnani girishramnani added this to For consideration in Sprint 191 via automation Oct 5, 2020
@girishramnani
Copy link
Contributor

girishramnani commented Oct 24, 2020

The behaviour we're seeing here is observed in more than just one place. For example:

$ odo service list -o json         
{
	"kind": "Error",
	"apiVersion": "odo.dev/v1alpha1",
	"metadata": {
		"creationTimestamp": null
	},
	"message": "Please specify the application name and project name\nOr use the command from inside a directory containing an odo component."
}

$ echo $?
1

The behaviour can be attributed to the use of LogErrorAndExit function which exits with os.Exit(1):

https://github.com/openshift/odo/blob/76f306ea5c23c64873828548a3ece33a03174241/pkg/odo/util/cmdutils.go#L56-L57

Changing the behaviour for one command and not for another would be a tough and messy task, I guess. Besides, it would lead to inconsistency and hence bad UX, IMO.

@jeffmaury under what circumstances would you, as a user, prefer exit code be 1 when executing -o json commands?

this is expected because there is an error in the way the command was used @dharmit .

but what @jeffmaury is mentioning is a valid bug. The idea with listing any resource is that it shouldn't error out when there are no services because that is not an error. It is an expected state when the user is starting their cluster.

@girishramnani
Copy link
Contributor

Now if the service catalog or operator hub is not enabled for the user then that should be an error because its something that we want the user to rectify.

@jeffmaury
Copy link
Member Author

Yes but from a tooling experience, this error should not be returned as a process exit code as the tooling will have no way to interpret it unless the error code are property documented so it should returned as a documented JSON output

@girishramnani girishramnani added this to For consideration in Sprint 192 via automation Oct 27, 2020
@girishramnani girishramnani removed this from For review in Sprint 191 Oct 27, 2020
@girishramnani girishramnani moved this from For consideration to For review in Sprint 192 Oct 27, 2020
Sprint 192 automation moved this from For review to Done Oct 29, 2020
@rm3l rm3l added the v2 Issue or PR that applies to the v2 of odo label Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. v2 Issue or PR that applies to the v2 of odo
Projects
Archived in project
Sprint 192
  
Done
5 participants