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

st2 CLI does not return errors as JSON / YAML #4218

Open
nmaludy opened this issue Jun 30, 2018 · 1 comment
Open

st2 CLI does not return errors as JSON / YAML #4218

nmaludy opened this issue Jun 30, 2018 · 1 comment

Comments

@nmaludy
Copy link
Member

nmaludy commented Jun 30, 2018

SUMMARY

When running the st2 CLI command with -j,--jso or -y,--yaml and an error occurs, the errors are printed as strings and not JSON or YAML.

ISSUE TYPE
  • Bug Report
STACKSTORM VERSION
$ st2 --version
st2 2.7.2, on Python 2.7
OS / ENVIRONMENT / INSTALL METHOD
$ cat /etc/redhat-release                                                                            
CentOS Linux release 7.5.1804 (Core) 

Install type = puppet-st2

STEPS TO REPRODUCE
$ st2 pack get --json fdsfdsfds
Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2client/commands/resource.py", line 165, in get_resource_by_pk
    instance = self.manager.get_by_id(pk, **kwargs)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2client/models/core.py", line 40, in decorate
    return func(*args, **kwargs)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2client/models/core.py", line 204, in get_by_id
    self.handle_error(response)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2client/models/core.py", line 166, in handle_error
    response.raise_for_status()
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/requests/models.py", line 928, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 401 Client Error: Unauthorized
MESSAGE: Unauthorized - One of Token or API key required. for url: http://127.0.0.1:9101/v1/packs/fdsfdsfds
ERROR: 401 Client Error: Unauthorized
MESSAGE: Unauthorized - One of Token or API key required. for url: http://127.0.0.1:9101/v1/packs/fdsfdsfds
$ st2 login -j -w st2admin
Password: 
Logged in as st2admin
$ st2 pack get --json fdsfsdfsd
Pack "fdsfsdfsd" is not found.
EXPECTED RESULTS

Error messages to be formated as JSON / YAML so they can be parsed programatically.

Example:

$ st2 pack get --json fdsfsdfsd
{
  "success": false.
  "failed": true,
  "error": {
    "type": "pack_not_found",
    "message": "Pack \"fdsfsdfsd\" is not found."
  }
}

Example:

$ st2 pack get --json fdsfsdfsd
{
  "success": false.
  "failed": true,
  "error": {
    "type": "unauthorized",
    "http_status": 401,
    "message": "Unauthorized - One of Token or API key required. for url: http://127.0.0.1:9101/v1/packs/fdsfdsfds"
    "exception_type": "requests.HTTPError"
    "traceback": [
      "Traceback (most recent call last):",
      "  File \"/opt/stackstorm/st2/lib/python2.7/site-packages/st2client/commands/resource.py\", line 165, in get_resource_by_pk",
      "    instance = self.manager.get_by_id(pk, **kwargs)",
      "  File \"/opt/stackstorm/st2/lib/python2.7/site-packages/st2client/models/core.py\", line 40, in decorate",
      "    return func(*args, **kwargs)",
      "  File \"/opt/stackstorm/st2/lib/python2.7/site-packages/st2client/models/core.py\", line 204, in get_by_id",
      "    self.handle_error(response)",
      "  File \"/opt/stackstorm/st2/lib/python2.7/site-packages/st2client/models/core.py\", line 166, in handle_error",
      "    response.raise_for_status()",
      "  File \"/opt/stackstorm/st2/lib/python2.7/site-packages/requests/models.py\", line 928, in raise_for_status",
      "    raise HTTPError(http_error_msg, response=self)"
    ]
  }
}
@arm4b arm4b added the bug label Jun 30, 2018
@Kami Kami added the CLI label Sep 3, 2018
@Kami
Copy link
Member

Kami commented Sep 3, 2018

Thanks for creating this issue.

I think it's a good feature request, but it won't be totally straight forward to implement since --json flag was really mostly intended just for list and get one commands.

Supporting it in every command will require quite some refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants