fix: remove bare excepts

This commit is contained in:
Ankush Menat
2021-09-01 14:40:56 +05:30
parent 331ec13012
commit 76f1ed624a
24 changed files with 42 additions and 42 deletions

View File

@@ -359,7 +359,7 @@ def make_gl_entries(doc, credit_account, debit_account, against,
try: try:
make_gl_entries(gl_entries, cancel=(doc.docstatus == 2), merge_entries=True) make_gl_entries(gl_entries, cancel=(doc.docstatus == 2), merge_entries=True)
frappe.db.commit() frappe.db.commit()
except: except Exception:
frappe.db.rollback() frappe.db.rollback()
traceback = frappe.get_traceback() traceback = frappe.get_traceback()
frappe.log_error(message=traceback) frappe.log_error(message=traceback)
@@ -430,7 +430,7 @@ def book_revenue_via_journal_entry(doc, credit_account, debit_account, against,
if submit: if submit:
journal_entry.submit() journal_entry.submit()
except: except Exception:
frappe.db.rollback() frappe.db.rollback()
traceback = frappe.get_traceback() traceback = frappe.get_traceback()
frappe.log_error(message=traceback) frappe.log_error(message=traceback)

View File

@@ -81,7 +81,7 @@ def filter_pricing_rule_based_on_condition(pricing_rules, doc=None):
try: try:
if frappe.safe_eval(pricing_rule.condition, None, doc.as_dict()): if frappe.safe_eval(pricing_rule.condition, None, doc.as_dict()):
filtered_pricing_rules.append(pricing_rule) filtered_pricing_rules.append(pricing_rule)
except: except Exception:
pass pass
else: else:
filtered_pricing_rules.append(pricing_rule) filtered_pricing_rules.append(pricing_rule)

View File

@@ -158,7 +158,7 @@ def get_recipients_and_cc(customer, doc):
if doc.cc_to != '': if doc.cc_to != '':
try: try:
cc=[frappe.get_value('User', doc.cc_to, 'email')] cc=[frappe.get_value('User', doc.cc_to, 'email')]
except: except Exception:
pass pass
return recipients, cc return recipients, cc

View File

@@ -648,7 +648,7 @@ def get_default_contact(doctype, name):
if out: if out:
try: try:
return out[0][0] return out[0][0]
except: except Exception:
return None return None
else: else:
return None return None

View File

@@ -546,7 +546,7 @@ class Asset(AccountsController):
cwip_account = None cwip_account = None
try: try:
cwip_account = get_asset_account("capital_work_in_progress_account", self.name, self.asset_category, self.company) cwip_account = get_asset_account("capital_work_in_progress_account", self.name, self.asset_category, self.company)
except: except Exception:
# if no cwip account found in category or company and "cwip is enabled" then raise else silently pass # if no cwip account found in category or company and "cwip is enabled" then raise else silently pass
if cwip_enabled: if cwip_enabled:
raise raise

View File

@@ -26,7 +26,7 @@ class SocialMediaPost(Document):
if self.scheduled_time: if self.scheduled_time:
self.post_status = "Scheduled" self.post_status = "Scheduled"
super(SocialMediaPost, self).submit() super(SocialMediaPost, self).submit()
def on_cancel(self): def on_cancel(self):
self.db_set('post_status', 'Cancelled') self.db_set('post_status', 'Cancelled')
@@ -35,11 +35,11 @@ class SocialMediaPost(Document):
if self.twitter and self.twitter_post_id: if self.twitter and self.twitter_post_id:
twitter = frappe.get_doc("Twitter Settings") twitter = frappe.get_doc("Twitter Settings")
twitter.delete_tweet(self.twitter_post_id) twitter.delete_tweet(self.twitter_post_id)
if self.linkedin and self.linkedin_post_id: if self.linkedin and self.linkedin_post_id:
linkedin = frappe.get_doc("LinkedIn Settings") linkedin = frappe.get_doc("LinkedIn Settings")
linkedin.delete_post(self.linkedin_post_id) linkedin.delete_post(self.linkedin_post_id)
self.db_set('post_status', 'Deleted') self.db_set('post_status', 'Deleted')
@frappe.whitelist() @frappe.whitelist()
@@ -51,7 +51,7 @@ class SocialMediaPost(Document):
if self.twitter and self.twitter_post_id: if self.twitter and self.twitter_post_id:
twitter = frappe.get_doc("Twitter Settings") twitter = frappe.get_doc("Twitter Settings")
response['twitter'] = twitter.get_tweet(self.twitter_post_id) response['twitter'] = twitter.get_tweet(self.twitter_post_id)
return response return response
@frappe.whitelist() @frappe.whitelist()
@@ -67,7 +67,7 @@ class SocialMediaPost(Document):
self.db_set("linkedin_post_id", linkedin_post.headers['X-RestLi-Id']) self.db_set("linkedin_post_id", linkedin_post.headers['X-RestLi-Id'])
self.db_set("post_status", "Posted") self.db_set("post_status", "Posted")
except: except Exception:
self.db_set("post_status", "Error") self.db_set("post_status", "Error")
title = _("Error while POSTING {0}").format(self.name) title = _("Error while POSTING {0}").format(self.name)
frappe.log_error(message=frappe.get_traceback(), title=title) frappe.log_error(message=frappe.get_traceback(), title=title)

View File

@@ -88,7 +88,7 @@ def simulate(domain='Manufacturing', days=100):
elif domain=='Education': elif domain=='Education':
edu.work() edu.work()
except: except Exception:
frappe.db.set_global('demo_last_date', current_date) frappe.db.set_global('demo_last_date', current_date)
raise raise
finally: finally:

View File

@@ -95,7 +95,7 @@ class CourseSchedulingTool(Document):
if self.day == calendar.day_name[getdate(d.schedule_date).weekday()]: if self.day == calendar.day_name[getdate(d.schedule_date).weekday()]:
frappe.delete_doc("Course Schedule", d.name) frappe.delete_doc("Course Schedule", d.name)
rescheduled.append(d.name) rescheduled.append(d.name)
except: except Exception:
reschedule_errors.append(d.name) reschedule_errors.append(d.name)
return rescheduled, reschedule_errors return rescheduled, reschedule_errors

View File

@@ -219,7 +219,7 @@ def get_quiz(quiz_name, course):
try: try:
quiz = frappe.get_doc("Quiz", quiz_name) quiz = frappe.get_doc("Quiz", quiz_name)
questions = quiz.get_questions() questions = quiz.get_questions()
except: except Exception:
frappe.throw(_("Quiz {0} does not exist").format(quiz_name), frappe.DoesNotExistError) frappe.throw(_("Quiz {0} does not exist").format(quiz_name), frappe.DoesNotExistError)
return None return None

View File

@@ -266,7 +266,7 @@ class TallyMigration(Document):
self.is_master_data_processed = 1 self.is_master_data_processed = 1
except: except Exception:
self.publish("Process Master Data", _("Process Failed"), -1, 5) self.publish("Process Master Data", _("Process Failed"), -1, 5)
self.log() self.log()
@@ -302,14 +302,14 @@ class TallyMigration(Document):
try: try:
party_doc = frappe.get_doc(party) party_doc = frappe.get_doc(party)
party_doc.insert() party_doc.insert()
except: except Exception:
self.log(party_doc) self.log(party_doc)
addresses_file = frappe.get_doc("File", {"file_url": addresses_file_url}) addresses_file = frappe.get_doc("File", {"file_url": addresses_file_url})
for address in json.loads(addresses_file.get_content()): for address in json.loads(addresses_file.get_content()):
try: try:
address_doc = frappe.get_doc(address) address_doc = frappe.get_doc(address)
address_doc.insert(ignore_mandatory=True) address_doc.insert(ignore_mandatory=True)
except: except Exception:
self.log(address_doc) self.log(address_doc)
def create_items_uoms(items_file_url, uoms_file_url): def create_items_uoms(items_file_url, uoms_file_url):
@@ -319,7 +319,7 @@ class TallyMigration(Document):
try: try:
uom_doc = frappe.get_doc(uom) uom_doc = frappe.get_doc(uom)
uom_doc.insert() uom_doc.insert()
except: except Exception:
self.log(uom_doc) self.log(uom_doc)
items_file = frappe.get_doc("File", {"file_url": items_file_url}) items_file = frappe.get_doc("File", {"file_url": items_file_url})
@@ -327,7 +327,7 @@ class TallyMigration(Document):
try: try:
item_doc = frappe.get_doc(item) item_doc = frappe.get_doc(item)
item_doc.insert() item_doc.insert()
except: except Exception:
self.log(item_doc) self.log(item_doc)
try: try:
@@ -346,7 +346,7 @@ class TallyMigration(Document):
self.is_master_data_imported = 1 self.is_master_data_imported = 1
frappe.db.commit() frappe.db.commit()
except: except Exception:
self.publish("Import Master Data", _("Process Failed"), -1, 5) self.publish("Import Master Data", _("Process Failed"), -1, 5)
frappe.db.rollback() frappe.db.rollback()
self.log() self.log()
@@ -370,7 +370,7 @@ class TallyMigration(Document):
if processed_voucher: if processed_voucher:
vouchers.append(processed_voucher) vouchers.append(processed_voucher)
frappe.db.commit() frappe.db.commit()
except: except Exception:
frappe.db.rollback() frappe.db.rollback()
self.log(voucher) self.log(voucher)
return vouchers return vouchers
@@ -494,7 +494,7 @@ class TallyMigration(Document):
self.is_day_book_data_processed = 1 self.is_day_book_data_processed = 1
except: except Exception:
self.publish("Process Day Book Data", _("Process Failed"), -1, 5) self.publish("Process Day Book Data", _("Process Failed"), -1, 5)
self.log() self.log()
@@ -564,7 +564,7 @@ class TallyMigration(Document):
is_last = True is_last = True
frappe.enqueue_doc(self.doctype, self.name, "_import_vouchers", queue="long", timeout=3600, start=index+1, total=total, is_last=is_last) frappe.enqueue_doc(self.doctype, self.name, "_import_vouchers", queue="long", timeout=3600, start=index+1, total=total, is_last=is_last)
except: except Exception:
self.log() self.log()
finally: finally:
@@ -583,7 +583,7 @@ class TallyMigration(Document):
voucher_doc.submit() voucher_doc.submit()
self.publish("Importing Vouchers", _("{} of {}").format(index, total), index, total) self.publish("Importing Vouchers", _("{} of {}").format(index, total), index, total)
frappe.db.commit() frappe.db.commit()
except: except Exception:
frappe.db.rollback() frappe.db.rollback()
self.log(voucher_doc) self.log(voucher_doc)

View File

@@ -48,7 +48,7 @@ class LabTest(Document):
if item.result_value and item.secondary_uom and item.conversion_factor: if item.result_value and item.secondary_uom and item.conversion_factor:
try: try:
item.secondary_uom_result = float(item.result_value) * float(item.conversion_factor) item.secondary_uom_result = float(item.result_value) * float(item.conversion_factor)
except: except Exception:
item.secondary_uom_result = '' item.secondary_uom_result = ''
frappe.msgprint(_('Row #{0}: Result for Secondary UOM not calculated').format(item.idx), title = _('Warning')) frappe.msgprint(_('Row #{0}: Result for Secondary UOM not calculated').format(item.idx), title = _('Warning'))

View File

@@ -82,7 +82,7 @@ class DailyWorkSummary(Document):
crop=True crop=True
) )
d.image = thumbnail_image d.image = thumbnail_image
except: except Exception:
d.image = original_image d.image = original_image
if d.sender in did_not_reply: if d.sender in did_not_reply:

View File

@@ -51,7 +51,7 @@ class LeaveControlPanel(Document):
la.docstatus = 1 la.docstatus = 1
la.save() la.save()
leave_allocated_for.append(d[0]) leave_allocated_for.append(d[0])
except: except Exception:
pass pass
if leave_allocated_for: if leave_allocated_for:
msgprint(_("Leaves Allocated Successfully for {0}").format(comma_and(leave_allocated_for))) msgprint(_("Leaves Allocated Successfully for {0}").format(comma_and(leave_allocated_for)))

View File

@@ -207,7 +207,7 @@ def get_member_based_on_subscription(subscription_id, email=None, customer_id=No
try: try:
return frappe.get_doc("Member", members[0]["name"]) return frappe.get_doc("Member", members[0]["name"])
except: except Exception:
return None return None
@@ -393,7 +393,7 @@ def notify_failure(log):
""".format(get_link_to_form("Error Log", log.name)) """.format(get_link_to_form("Error Log", log.name))
sendmail_to_system_managers("[Important] [ERPNext] Razorpay membership webhook failed , please check.", content) sendmail_to_system_managers("[Important] [ERPNext] Razorpay membership webhook failed , please check.", content)
except: except Exception:
pass pass
@@ -402,7 +402,7 @@ def get_plan_from_razorpay_id(plan_id):
try: try:
return plan[0]["name"] return plan[0]["name"]
except: except Exception:
return None return None

View File

@@ -30,7 +30,7 @@ def execute():
buying_cost_center, selling_cost_center, expense_account, income_account, default_supplier buying_cost_center, selling_cost_center, expense_account, income_account, default_supplier
FROM `tabItem`; FROM `tabItem`;
''', companies[0].name) ''', companies[0].name)
except: except Exception:
pass pass
else: else:
item_details = frappe.db.sql(""" SELECT name, default_warehouse, item_details = frappe.db.sql(""" SELECT name, default_warehouse,

View File

@@ -11,5 +11,5 @@ def execute():
frappe.reload_doc("stock", "doctype", "stock_ledger_entry") frappe.reload_doc("stock", "doctype", "stock_ledger_entry")
frappe.reload_doc("stock", "doctype", "serial_no") frappe.reload_doc("stock", "doctype", "serial_no")
except: except Exception:
pass pass

View File

@@ -86,7 +86,7 @@ def execute():
try: try:
employee_other_income.submit() employee_other_income.submit()
migrated.append([proof.employee, proof.payroll_period]) migrated.append([proof.employee, proof.payroll_period])
except: except Exception:
pass pass
if not frappe.db.table_exists("Employee Tax Exemption Declaration"): if not frappe.db.table_exists("Employee Tax Exemption Declaration"):
@@ -108,5 +108,5 @@ def execute():
try: try:
employee_other_income.submit() employee_other_income.submit()
except: except Exception:
pass pass

View File

@@ -20,5 +20,5 @@ def execute():
}) })
if count % 200 == 0: if count % 200 == 0:
frappe.db.commit() frappe.db.commit()
except: except Exception:
frappe.db.rollback() frappe.db.rollback()

View File

@@ -106,7 +106,7 @@ def fin(args):
def make_sample_data(domains): def make_sample_data(domains):
try: try:
sample_data.make_sample_data(domains) sample_data.make_sample_data(domains)
except: except Exception:
# clear message # clear message
if frappe.message_log: if frappe.message_log:
frappe.message_log.pop() frappe.message_log.pop()

View File

@@ -109,7 +109,7 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No
value = response.json()["result"] value = response.json()["result"]
cache.setex(name=key, time=21600, value=flt(value)) cache.setex(name=key, time=21600, value=flt(value))
return flt(value) return flt(value)
except: except Exception:
frappe.log_error(title="Get Exchange Rate") frappe.log_error(title="Get Exchange Rate")
frappe.msgprint(_("Unable to find exchange rate for {0} to {1} for key date {2}. Please create a Currency Exchange record manually").format(from_currency, to_currency, transaction_date)) frappe.msgprint(_("Unable to find exchange rate for {0} to {1} for key date {2}. Please create a Currency Exchange record manually").format(from_currency, to_currency, transaction_date))
return 0.0 return 0.0

View File

@@ -331,7 +331,7 @@ class DeliveryNote(SellingController):
credit_note_link = frappe.utils.get_link_to_form('Sales Invoice', return_invoice.name) credit_note_link = frappe.utils.get_link_to_form('Sales Invoice', return_invoice.name)
frappe.msgprint(_("Credit Note {0} has been created automatically").format(credit_note_link)) frappe.msgprint(_("Credit Note {0} has been created automatically").format(credit_note_link))
except: except Exception:
frappe.throw(_("Could not create Credit Note automatically, please uncheck 'Issue Credit Note' and submit again")) frappe.throw(_("Could not create Credit Note automatically, please uncheck 'Issue Credit Note' and submit again"))
def update_billed_amount_based_on_so(so_detail, update_modified=True): def update_billed_amount_based_on_so(so_detail, update_modified=True):

View File

@@ -573,7 +573,7 @@ def auto_fetch_serial_number(qty, item_code, warehouse, posting_date=None, batch
if batch_nos: if batch_nos:
try: try:
filters["batch_no"] = json.loads(batch_nos) if (type(json.loads(batch_nos)) == list) else [json.loads(batch_nos)] filters["batch_no"] = json.loads(batch_nos) if (type(json.loads(batch_nos)) == list) else [json.loads(batch_nos)]
except: except Exception:
filters["batch_no"] = [batch_nos] filters["batch_no"] = [batch_nos]
if posting_date: if posting_date:

View File

@@ -166,7 +166,7 @@ def create_material_request(material_requests):
mr.submit() mr.submit()
mr_list.append(mr) mr_list.append(mr)
except: except Exception:
_log_exception() _log_exception()
if mr_list: if mr_list:

View File

@@ -29,7 +29,7 @@ def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False,
try: try:
repost_stock(d[0], d[1], allow_zero_rate, only_actual, only_bin, allow_negative_stock) repost_stock(d[0], d[1], allow_zero_rate, only_actual, only_bin, allow_negative_stock)
frappe.db.commit() frappe.db.commit()
except: except Exception:
frappe.db.rollback() frappe.db.rollback()
if allow_negative_stock: if allow_negative_stock:
@@ -247,5 +247,5 @@ def reset_serial_no_status_and_warehouse(serial_nos=None):
sr.via_stock_ledger = True sr.via_stock_ledger = True
sr.save() sr.save()
except: except Exception:
pass pass