Skip to content

Commit

Permalink
fix: Correctly extract last message
Browse files Browse the repository at this point in the history
frappe.message_log now contains plain dictionary and not JSON strings,
so no need to load them.
  • Loading branch information
ankush committed Oct 20, 2023
1 parent 40cdde8 commit e8571ba
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def create_merge_logs(invoice_by_customer, closing_entry=None):
except Exception as e:
frappe.db.rollback()
message_log = frappe.message_log.pop() if frappe.message_log else str(e)
error_message = safe_load_json(message_log)
error_message = get_error_message(message_log)

if closing_entry:
closing_entry.set_status(update=True, status="Failed")
Expand Down Expand Up @@ -483,7 +483,7 @@ def cancel_merge_logs(merge_logs, closing_entry=None):
except Exception as e:
frappe.db.rollback()
message_log = frappe.message_log.pop() if frappe.message_log else str(e)
error_message = safe_load_json(message_log)
error_message = get_error_message(message_log)

if closing_entry:
closing_entry.set_status(update=True, status="Submitted")
Expand Down Expand Up @@ -525,10 +525,8 @@ def check_scheduler_status():
frappe.throw(_("Scheduler is inactive. Cannot enqueue job."), title=_("Scheduler Inactive"))


def safe_load_json(message):
def get_error_message(message) -> str:
try:
json_message = json.loads(message).get("message")
return message["message"]
except Exception:
json_message = message

return json_message
return str(message)

0 comments on commit e8571ba

Please sign in to comment.