Skip to content

Parse errors does not reach correct block #1846

@kmosti

Description

@kmosti

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions