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

Handle aws and git cli failures #26

Closed
Nr18 opened this issue Feb 8, 2022 · 0 comments
Closed

Handle aws and git cli failures #26

Nr18 opened this issue Feb 8, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@Nr18
Copy link
Collaborator

Nr18 commented Feb 8, 2022

The pull-request-codecommit tool is in essence a wrapper around git and the aws commands. It could happen that those tools raise errors like for example:

An error occurred (ExpiredTokenException) when calling the ListPullRequests operation: The security token included in the request is expired

Or:

An error occurred (AccessDenied) when calling the XXX operation: User: XXX is not authorized to perform: XXX

What were you trying to accomplish?

When you interact with the the AWS CLI it could happen that the token is expired. This can happen when you copy STS tokens in the config file or you use STS tokens as an export.

Expected Behavior

Graceful error message

Current Behavior

Throws a stack trace

Possible Solution

Add some logic that checks the response and if it succeeded yes/no

Steps to Reproduce (for bugs)

  1. Get outdated STS tokens or use IAM user without the correct IAM policies
  2. Try to create a repository

Environment

  • pull-request-codecommit version used: 0.2.0
  • Debugging logs
An error occurred (ExpiredTokenException) when calling the ListPullRequests operation: The security token included in the request is expired
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "redacted/virtualenvs/pull-request-codecommit-pNTLxWre-py3.8/lib/python3.8/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "redacted/virtualenvs/pull-request-codecommit-pNTLxWre-py3.8/lib/python3.8/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "redacted/virtualenvs/pull-request-codecommit-pNTLxWre-py3.8/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "redacted/virtualenvs/pull-request-codecommit-pNTLxWre-py3.8/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "redacted/pull-request-codecommit/pull_request_codecommit/__init__.py", line 18, in main
    pr = __create_pull_request(repo)
  File "redacted/pull-request-codecommit/pull_request_codecommit/__init__.py", line 43, in __create_pull_request
    __propose_title_description(pr)
  File "redacted/pull-request-codecommit/pull_request_codecommit/__init__.py", line 64, in __propose_title_description
    message = click.edit(f"{pr.title}\n\n{pr.description}")
  File "redacted/pull-request-codecommit/pull_request_codecommit/pull_request.py", line 31, in title
    return self.proposal.title
  File "redacted/pull-request-codecommit/pull_request_codecommit/pull_request_proposal.py", line 28, in title
    if self.__pull_request.title:
  File "redacted/pull-request-codecommit/pull_request_codecommit/pull_request_codecommit.py", line 47, in title
    return self.__data.get("title", "")
  File "redacted/pull-request-codecommit/pull_request_codecommit/pull_request_codecommit.py", line 20, in __data
    self.__raw_data = self.__client.get_open_pull_request(
  File "redacted/pull-request-codecommit/pull_request_codecommit/aws/client.py", line 52, in get_open_pull_request
    data = json.loads(response)
  File "redacted/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "redacted/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "redacted/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
An error occurred (ManualMergeRequiredException) when calling the MergePullRequestByFastForward operation: Current branches cannot be merged, please try to merge using a Git client locally.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "redacted/virtualenvs/pull-request-codecommit-pNTLxWre-py3.8/lib/python3.8/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "redacted/virtualenvs/pull-request-codecommit-pNTLxWre-py3.8/lib/python3.8/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "redacted/virtualenvs/pull-request-codecommit-pNTLxWre-py3.8/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "redacted/virtualenvs/pull-request-codecommit-pNTLxWre-py3.8/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "redacted/pull-request-codecommit/pull_request_codecommit/__init__.py", line 21, in main
    status = pr.merge()
  File "redacted/pull-request-codecommit/pull_request_codecommit/pull_request.py", line 53, in merge
    return self.__pull_request.merge()
  File "redacted/pull-request-codecommit/pull_request_codecommit/pull_request_codecommit.py", line 65, in merge
    response = self.__client.merge_pull_request(
  File "redacted/pull-request-codecommit/pull_request_codecommit/aws/client.py", line 133, in merge_pull_request
    data = json.loads(response)
  File "redacted/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "redacted/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "redacted/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
@Nr18 Nr18 added the bug Something isn't working label Feb 8, 2022
@Nr18 Nr18 changed the title Handle AWS CLI failures Handle aws and git cli failures Feb 8, 2022
Nr18 pushed a commit that referenced this issue Feb 20, 2022
By catching the stderr and error codes from the aws and git executions we render a proper error message.

Issue: #26
@Nr18 Nr18 closed this as completed Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant