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

Parse errors does not reach correct block #1846

Open
2 of 4 tasks
kmosti opened this issue Mar 25, 2024 · 1 comment
Open
2 of 4 tasks

Parse errors does not reach correct block #1846

kmosti opened this issue Mar 25, 2024 · 1 comment

Comments

@kmosti
Copy link

kmosti commented Mar 25, 2024

Bug summary

elif "errorMessage" in resp_data:
# Sometimes Jira returns `errorMessage` as a message error key
# for example for the "Service temporary unavailable" error
parsed_errors = [resp_data["errorMessage"]]
elif "errorMessages" in resp_data:
# Jira 5.0.x error messages sometimes come wrapped in this array
# Sometimes this is present but empty
error_messages = resp_data["errorMessages"]
if len(error_messages) > 0:
if isinstance(error_messages, (list, tuple)):
parsed_errors = list(error_messages)
else:
parsed_errors = [error_messages]
elif "errors" in resp_data:

elif statements here causes the final block to not be executed when e.g. errorMessages is present, empty, but there is an errors array also in the returned error text.

For example, with the below content within error.text, parse_errors will always return an empty List:

{"errorMessages":[],"errors":{"assignee":"User \'[email protected]\' does not exist."}}

Changing the elif statements to if would ensure that the parser reaches the if "errors" in resp_data: block.

Is there an existing issue for this?

  • I have searched the existing issues

Jira Instance type

Jira Server or Data Center (Self-hosted)

Jira instance version

v9.14.0

jira-python version

3.6.0

Python Interpreter version

3.11.8

Which operating systems have you used?

  • Linux
  • macOS
  • Windows

Reproduction steps

# 1. When I try to update an issue with a non-existing user as the assignee
# I want to catch that we have a "User foo@bar does not exist" type error, so I need to parse the returned error messages.

def update_assigned(self, incident_id: str, owner: Owner):
    self._update_token_silent()
    self._logger.info(
        "(TEST) Changing assignee for incident with id '%s' in JIRA: %s",
        incident_id,
        owner.email,
    )
    update: Dict = {"assignee": [{"set": {"name": owner.email}}]}
    try:
        jira_incident = self._get_issue(incident_id)
        jira_incident.update(update=update)
    except JIRAError as e:
        parsed_errors = self._parse_errors(e.response)
        # if pattern in parsed_errors, handle in some way
        self._logger.error("Error during update of JIRA issue: %s", e)
        return
    self._logger.info("Updated issue: %s", jira_incident.permalink())


# 2. When I call the function with a non existing user, parsed_errors is always empty

Stack trace

N/A

Expected behaviour

I would expect the function to return a list of error messages from the server error response.

Additional Context

No response

@kmosti
Copy link
Author

kmosti commented Apr 3, 2024

I made a PR here with a proposed solution:
#1854

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

No branches or pull requests

1 participant