Skip to content

Commit

Permalink
fix(minor): update frappe.error_log to new API (frappe#30864)
Browse files Browse the repository at this point in the history
* fix(minor): update frappe.error_log to new API

* refactor: changes for updated log_error api

Co-authored-by: Ankush Menat <ankush@frappe.io>
  • Loading branch information
2 people authored and hrwX committed May 10, 2022
1 parent 92c8ff3 commit 2d06610
Show file tree
Hide file tree
Showing 33 changed files with 58 additions and 100 deletions.
19 changes: 3 additions & 16 deletions erpnext/accounts/deferred_revenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,19 +539,11 @@ def make_gl_entries(
frappe.db.commit()
except Exception as e:
if frappe.flags.in_test:
traceback = frappe.get_traceback()
frappe.log_error(
title=_("Error while processing deferred accounting for Invoice {0}").format(doc.name),
message=traceback,
)
doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}")
raise e
else:
frappe.db.rollback()
traceback = frappe.get_traceback()
frappe.log_error(
title=_("Error while processing deferred accounting for Invoice {0}").format(doc.name),
message=traceback,
)
doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}")
frappe.flags.deferred_accounting_error = True


Expand Down Expand Up @@ -632,12 +624,7 @@ def book_revenue_via_journal_entry(
frappe.db.commit()
except Exception:
frappe.db.rollback()
traceback = frappe.get_traceback()
frappe.log_error(
title=_("Error while processing deferred accounting for Invoice {0}").format(doc.name),
message=traceback,
)

doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}")
frappe.flags.deferred_accounting_error = True


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def start_import(
except Exception:
frappe.db.rollback()
data_import.db_set("status", "Error")
frappe.log_error(title=data_import.name)
data_import.log_error("Bank Statement Import failed")
finally:
frappe.flags.in_import = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create_bank_entries(columns, data, bank_account):
bank_transaction.submit()
success += 1
except Exception:
frappe.log_error(frappe.get_traceback())
bank_transaction.log_error("Bank entry creation failed")
errors += 1

return {"success": success, "errors": errors}
Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/doctype/ledger_merge/ledger_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def start_merge(docname):
)
except Exception:
frappe.db.rollback()
frappe.log_error(title=ledger_merge.name)
ledger_merge.log_error("Ledger merge failed")
finally:
if successful_merges == total:
ledger_merge.db_set("status", "Success")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# For license information, please see license.txt


import traceback
from json import dumps

import frappe
from frappe import _, scrub
from frappe.model.document import Document
Expand Down Expand Up @@ -247,11 +244,7 @@ def start_import(invoices):
except Exception:
errors += 1
frappe.db.rollback()
message = "\n".join(
["Data:", dumps(d, default=str, indent=4), "--" * 50, "\nException:", traceback.format_exc()]
)
frappe.log_error(title="Error while creating Opening Invoice", message=message)
frappe.db.commit()
doc.log_error("Opening invoice creation failed")
if errors:
frappe.msgprint(
_("You had {} errors while creating opening invoices. Check {} for more details").format(
Expand Down
6 changes: 0 additions & 6 deletions erpnext/accounts/doctype/subscription/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def update_subscription_period(self, date: Optional[Union[datetime.date, str]] =
"""
Subscription period is the period to be billed. This method updates the
beginning of the billing period and end of the billing period.
The beginning of the billing period is represented in the doctype as
`current_invoice_start` and the end of the billing period is represented
as `current_invoice_end`.
Expand Down Expand Up @@ -89,10 +88,8 @@ def get_current_invoice_end(
) -> Union[datetime.date, str]:
"""
This returns the date of the end of the current billing period.
If the subscription is in trial period, it will be set as the end of the
trial period.
If is not in a trial period, it will be `x` days from the beginning of the
current billing period where `x` is the billing interval from the
`Subscription Plan` in the `Subscription`.
Expand Down Expand Up @@ -143,7 +140,6 @@ def validate_plans_billing_cycle(billing_cycle_data: List[Dict[str, str]]) -> No
def get_billing_cycle_and_interval(self) -> List[Dict[str, str]]:
"""
Returns a dict representing the billing interval and cycle for this `Subscription`.
You shouldn't need to call this directly. Use `get_billing_cycle` instead.
"""
plan_names = [plan.plan for plan in self.plans]
Expand All @@ -158,7 +154,6 @@ def get_billing_cycle_and_interval(self) -> List[Dict[str, str]]:
def get_billing_cycle_data(self) -> Dict[str, int]:
"""
Returns dict contain the billing cycle data.
You shouldn't need to call this directly. Use `get_billing_cycle` instead.
"""
billing_info = self.get_billing_cycle_and_interval()
Expand Down Expand Up @@ -326,7 +321,6 @@ def generate_invoice(
"""
Creates a `Invoice` for the `Subscription`, updates `self.invoices` and
saves the `Subscription`.
Backwards compatibility
"""
return self.create_invoice(from_date=from_date, to_date=to_date)
Expand Down
2 changes: 1 addition & 1 deletion erpnext/crm/doctype/linkedin_settings/linkedin_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def post(self, text, title, media=None):
if media_id:
return self.post_text(text, title, media_id=media_id)
else:
frappe.log_error("Failed to upload media.", "LinkedIn Upload Error")
self.log_error("LinkedIn: Failed to upload media")

def upload_image(self, media):
media = get_file_path(media)
Expand Down
3 changes: 1 addition & 2 deletions erpnext/crm/doctype/social_media_post/social_media_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def post(self):

except Exception:
self.db_set("post_status", "Error")
title = _("Error while POSTING {0}").format(self.name)
frappe.log_error(message=frappe.get_traceback(), title=title)
self.log_error("Social posting failed")


def process_scheduled_social_media_posts():
Expand Down
3 changes: 1 addition & 2 deletions erpnext/e_commerce/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def get_product_filter_data(query_args=None):
attribute_filters, field_filters, search_term=search, start=start, item_group=item_group
)
except Exception:
traceback = frappe.get_traceback()
frappe.log_error(traceback, frappe._("Product Engine Error"))
frappe.log_error("Product query with filter failed")
return {"exc": "Something went wrong!"}

# discount filter data
Expand Down
3 changes: 1 addition & 2 deletions erpnext/e_commerce/redisearch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ def get_fields_indexed():

def raise_redisearch_error():
"Create an Error Log and raise error."
traceback = frappe.get_traceback()
log = frappe.log_error(traceback, frappe._("Redisearch Error"))
log = frappe.log_error("Redisearch Error")
log_link = frappe.utils.get_link_to_form("Error Log", log.name)

frappe.throw(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def order(*args, **kwargs):
error_message = (
frappe.get_traceback() + "\n\n Request Data: \n" + json.loads(frappe.request.data).__str__()
)
frappe.log_error(error_message, "WooCommerce Error")
frappe.log_error("WooCommerce Error", error_message)
raise


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def create_payment_request(self, data):
return self.create_charge_on_gocardless()

except Exception:
frappe.log_error(frappe.get_traceback())
frappe.log_error("Gocardless payment reqeust failed")
return {
"redirect_to": frappe.redirect_to_message(
_("Server Error"),
Expand Down Expand Up @@ -163,21 +163,15 @@ def create_charge_on_gocardless(self):
or payment.status == "charged_back"
):
self.integration_request.db_set("status", "Cancelled", update_modified=False)
frappe.log_error(
_("Payment Cancelled. Please check your GoCardless Account for more details"),
"GoCardless Payment Error",
)
frappe.log_error("Gocardless payment cancelled")
self.integration_request.db_set("error", payment.status, update_modified=False)
else:
self.integration_request.db_set("status", "Failed", update_modified=False)
frappe.log_error(
_("Payment Failed. Please check your GoCardless Account for more details"),
"GoCardless Payment Error",
)
frappe.log_error("Gocardless payment failed")
self.integration_request.db_set("error", payment.status, update_modified=False)

except Exception as e:
frappe.log_error(e, "GoCardless Payment Error")
frappe.log_error("GoCardless Payment Error")

if self.flags.status_changed_to == "Completed":
status = "Completed"
Expand All @@ -188,7 +182,7 @@ def create_charge_on_gocardless(self):
self.data.get("reference_doctype"), self.data.get("reference_docname")
).run_method("on_payment_authorized", self.flags.status_changed_to)
except Exception:
frappe.log_error(frappe.get_traceback())
frappe.log_error("Gocardless redirect failed")

if custom_redirect_to:
redirect_to = custom_redirect_to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def generate_stk_push(**kwargs):
return response

except Exception:
frappe.log_error(title=_("Mpesa Express Transaction Error"))
frappe.log_error("Mpesa Express Transaction Error")
frappe.throw(
_("Issue detected with Mpesa configuration, check the error logs for more details"),
title=_("Mpesa Express Error"),
Expand Down Expand Up @@ -203,7 +203,7 @@ def verify_transaction(**kwargs):
integration_request.handle_success(transaction_response)
except Exception:
integration_request.handle_failure(transaction_response)
frappe.log_error(frappe.get_traceback())
frappe.log_error("Mpesa: Failed to verify transaction")

else:
integration_request.handle_failure(transaction_response)
Expand Down Expand Up @@ -275,7 +275,7 @@ def get_account_balance(request_payload):
)
return response
except Exception:
frappe.log_error(title=_("Account Balance Processing Error"))
frappe.log_error("Mpesa: Failed to get account balance")
frappe.throw(_("Please check your configuration and try again"), title=_("Error"))


Expand Down Expand Up @@ -315,7 +315,7 @@ def process_balance_info(**kwargs):
except Exception:
request.handle_failure(account_balance_response)
frappe.log_error(
title=_("Mpesa Account Balance Processing Error"), message=account_balance_response
title="Mpesa Account Balance Processing Error", message=account_balance_response
)
else:
request.handle_failure(account_balance_response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, access_token=None):

def get_access_token(self, public_token):
if public_token is None:
frappe.log_error(_("Public token is missing for this bank"), _("Plaid public token error"))
frappe.log_error("Plaid: Public token is missing")
response = self.client.Item.public_token.exchange(public_token)
access_token = response["access_token"]
return access_token
Expand Down Expand Up @@ -61,10 +61,10 @@ def get_link_token(self, update_mode=False):
try:
response = self.client.LinkToken.create(token_request)
except InvalidRequestError:
frappe.log_error(frappe.get_traceback(), _("Plaid invalid request error"))
frappe.log_error("Plaid: Invalid request error")
frappe.msgprint(_("Please check your Plaid client ID and secret values"))
except APIError as e:
frappe.log_error(frappe.get_traceback(), _("Plaid authentication error"))
frappe.log_error("Plaid: Authentication error")
frappe.throw(_(str(e)), title=_("Authentication Failed"))
else:
return response["link_token"]
Expand All @@ -81,7 +81,7 @@ def auth(self):
except requests.Timeout:
pass
except Exception as e:
frappe.log_error(frappe.get_traceback(), _("Plaid authentication error"))
frappe.log_error("Plaid: Authentication error")
frappe.throw(_(str(e)), title=_("Authentication Failed"))

def get_transactions(self, start_date, end_date, account_id=None):
Expand All @@ -102,4 +102,4 @@ def get_transactions(self, start_date, end_date, account_id=None):
except ItemError as e:
raise e
except Exception:
frappe.log_error(frappe.get_traceback(), _("Plaid transactions sync error"))
frappe.log_error("Plaid: Transactions sync error")
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def add_institution(token, response):
)
bank.insert()
except Exception:
frappe.log_error(frappe.get_traceback(), title=_("Plaid Link Error"))
frappe.log_error("Plaid Link Error")
else:
bank = frappe.get_doc("Bank", response["institution"]["name"])
bank.plaid_access_token = access_token
Expand Down Expand Up @@ -113,7 +113,7 @@ def add_bank_accounts(response, bank, company):
_("Bank account {0} already exists and could not be created again").format(account["name"])
)
except Exception:
frappe.log_error(frappe.get_traceback(), title=_("Plaid Link Error"))
frappe.log_error("Plaid Link Error")
frappe.throw(
_("There was an error creating Bank Account while linking with Plaid."),
title=_("Plaid Link Failed"),
Expand All @@ -135,7 +135,7 @@ def add_bank_accounts(response, bank, company):
existing_account.save()
result.append(existing_bank_account)
except Exception:
frappe.log_error(frappe.get_traceback(), title=_("Plaid Link Error"))
frappe.log_error("Plaid Link Error")
frappe.throw(
_("There was an error updating Bank Account {} while linking with Plaid.").format(
existing_bank_account
Expand Down
4 changes: 1 addition & 3 deletions erpnext/erpnext_integrations/exotel_integration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import frappe
import requests
from frappe import _

# api/method/erpnext.erpnext_integrations.exotel_integration.handle_incoming_call
# api/method/erpnext.erpnext_integrations.exotel_integration.handle_end_call
Expand All @@ -26,8 +25,7 @@ def handle_incoming_call(**kwargs):
update_call_log(call_payload, call_log=call_log)
except Exception as e:
frappe.db.rollback()
frappe.log_error(title=_("Error in Exotel incoming call"))
frappe.db.commit()
exotel_settings.log_error("Error in Exotel incoming call")


@frappe.whitelist(allow_guest=True)
Expand Down
6 changes: 3 additions & 3 deletions erpnext/erpnext_integrations/stripe_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def create_stripe_subscription(gateway_controller, data):
return create_subscription_on_stripe(stripe_settings)

except Exception:
frappe.log_error(frappe.get_traceback())
stripe_settings.log_error("Unable to create Stripe subscription")
return {
"redirect_to": frappe.redirect_to_message(
_("Server Error"),
Expand Down Expand Up @@ -55,9 +55,9 @@ def create_subscription_on_stripe(stripe_settings):

else:
stripe_settings.integration_request.db_set("status", "Failed", update_modified=False)
frappe.log_error("Subscription N°: " + subscription.id, "Stripe Payment not completed")
frappe.log_error(f"Stripe Subscription ID {subscription.id}: Payment failed")
except Exception:
stripe_settings.integration_request.db_set("status", "Failed", update_modified=False)
frappe.log_error(frappe.get_traceback())
stripe_settings.log_error("Unable to create Stripe subscription")

return stripe_settings.finalize_request()
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def run_bom_job(

except Exception:
frappe.db.rollback()
error_log = frappe.log_error(message=frappe.get_traceback(), title=_("BOM Update Tool Error"))
error_log = doc.log_error("BOM Update Tool Error")

doc.db_set("status", "Failed")
doc.db_set("error_log", error_log.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def execute():
"""
)
except Exception as e:
frappe.log_error(e, title="Patch Migration Failed")
frappe.log_error("Bank to Bank Account patch migration failed")

frappe.reload_doc("accounts", "doctype", "bank_account")
frappe.reload_doc("accounts", "doctype", "payment_request")
3 changes: 1 addition & 2 deletions erpnext/patches/v13_0/add_missing_fg_item_for_stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ def repost_stock_entry(doc):
make_sl_entries(sl_entries, True)
except Exception:
print(f"SLE entries not posted for the stock entry {doc.name}")
traceback = frappe.get_traceback()
frappe.log_error(traceback)
doc.log_error("Stock respost failed")


def get_sle_for_target_warehouse(doc, sl_entries, finished_item_row):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,5 @@ def make_new_website_item(item: str) -> Union[str, None]:
web_item = make_website_item(doc) # returns [website_item.name, item_name]
return web_item[0]
except Exception:
title = f"{item}: Error while converting to Website Item "
frappe.log_error(
title + "for Item Card Group Template" + "\n\n" + frappe.get_traceback(), title=title
)
doc.log_error("Website Item creation failed")
return None
Loading

0 comments on commit 2d06610

Please sign in to comment.