Skip to content

Commit 57be4aa

Browse files
authored
Merge pull request #1078 from closeio/andrzej/p3/fix-ruff-g201
Fix ruff `G201` error
2 parents c314b6b + ed1123d commit 57be4aa

File tree

13 files changed

+24
-54
lines changed

13 files changed

+24
-54
lines changed

inbox/api/metrics_api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,9 @@ def index(): # type: ignore[no-untyped-def] # noqa: ANN201
256256
}
257257
)
258258
except Exception:
259-
log.error( # noqa: G201
259+
log.exception(
260260
"Error while serializing account metrics",
261261
account_id=account.id,
262-
exc_info=True,
263262
)
264263

265264
return APIEncoder().jsonify(data)

inbox/api/ns_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def handle_operational_error(error): # type: ignore[no-untyped-def] # noqa: AN
265265
else:
266266
message = "A temporary database error prevented us from serving this request. Please try again."
267267

268-
log.error("MySQL OperationalError", exc_info=True)
268+
log.exception("MySQL OperationalError")
269269
response = flask_jsonify(message=message, type="database_error")
270270
response.status_code = 503
271271
return response

inbox/events/recurring.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,8 @@ def parse_rrule(event): # type: ignore[no-untyped-def] # noqa: ANN201
8888
)
8989

9090
return rule
91-
except Exception as e:
92-
log.error( # noqa: G201
93-
"Error parsing RRULE entry",
94-
event_id=event.id,
95-
error=e,
96-
exc_info=True,
97-
)
91+
except Exception:
92+
log.exception("Error parsing RRULE entry", event_id=event.id)
9893
return None
9994

10095

inbox/heartbeat/store.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ def wrapper(*args, **kwargs): # type: ignore[no-untyped-def]
1717
try:
1818
return f(*args, **kwargs)
1919
except Exception:
20-
log.error( # noqa: G201
21-
"Error interacting with heartbeats", exc_info=True
22-
)
20+
log.exception("Error interacting with heartbeats")
2321

2422
return wrapper
2523

@@ -87,12 +85,11 @@ def publish(self, **kwargs) -> None: # type: ignore[no-untyped-def]
8785
self.store.publish(self.key, self.heartbeat_at)
8886
except Exception:
8987
log = get_logger()
90-
log.error( # noqa: G201
88+
log.exception(
9189
"Error while writing the heartbeat status",
9290
account_id=self.key.account_id,
9391
folder_id=self.key.folder_id,
9492
device_id=self.device_id,
95-
exc_info=True,
9693
)
9794

9895
@safe_failure

inbox/mailsync/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ def start_sync(self, account_id: int) -> bool:
392392
sync_host=account.sync_host,
393393
)
394394
except Exception:
395-
self.log.error( # noqa: G201
396-
"Error starting sync", exc_info=True, account_id=account_id
395+
self.log.exception(
396+
"Error starting sync", account_id=account_id
397397
)
398398
return False
399399
return True

inbox/models/event.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -509,26 +509,16 @@ def __init__(self, **kwargs) -> None: # type: ignore[no-untyped-def]
509509
super().__init__(**kwargs)
510510
try:
511511
self.unwrap_rrule()
512-
except Exception as e:
513-
log.error( # noqa: G201
514-
"Error parsing RRULE entry",
515-
event_id=self.id,
516-
error=e,
517-
exc_info=True,
518-
)
512+
except Exception:
513+
log.exception("Error parsing RRULE entry", event_id=self.id)
519514

520515
# FIXME @karim: use an overrided property instead of a reconstructor.
521516
@reconstructor
522517
def reconstruct(self) -> None:
523518
try:
524519
self.unwrap_rrule()
525-
except Exception as e:
526-
log.error( # noqa: G201
527-
"Error parsing stored RRULE entry",
528-
event_id=self.id,
529-
error=e,
530-
exc_info=True,
531-
)
520+
except Exception:
521+
log.exception("Error parsing stored RRULE entry", event_id=self.id)
532522

533523
def inflate(self, start=None, end=None): # type: ignore[no-untyped-def] # noqa: ANN201
534524
# Convert a RecurringEvent into a series of InflatedEvents

inbox/models/message.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,8 @@ def calculate_html_snippet(self, text: str) -> str:
708708
try:
709709
text = strip_tags(text)
710710
except HTMLParseError:
711-
log.error( # noqa: G201
712-
"error stripping tags",
713-
message_nylas_uid=self.nylas_uid,
714-
exc_info=True,
711+
log.exception(
712+
"error stripping tags", message_nylas_uid=self.nylas_uid
715713
)
716714
text = ""
717715

inbox/s3/backends/imap.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ def get_imap_raw_contents(message): # type: ignore[no-untyped-def] # noqa: ANN
2323
try:
2424
crispin_client.select_folder(folder.name, uidvalidity_cb)
2525
except FolderMissingError as exc:
26-
log.error( # noqa: G201
26+
log.exception(
2727
"Error while fetching raw contents: can't find folder",
28-
exc_info=True,
2928
logstash_tag="fetching_error",
3029
)
3130
raise EmailFetchException(
@@ -42,9 +41,8 @@ def get_imap_raw_contents(message): # type: ignore[no-untyped-def] # noqa: ANN
4241

4342
return uids[0].body
4443
except imapclient.IMAPClient.Error:
45-
log.error( # noqa: G201
44+
log.exception(
4645
"Error while fetching raw contents",
47-
exc_info=True,
4846
logstash_tag="fetching_error",
4947
)
5048
raise EmailFetchException( # noqa: B904

inbox/search/backends/imap.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,8 @@ def _search_folder( # type: ignore[no-untyped-def]
233233
self.log.warning("Won't search missing IMAP folder", exc_info=True)
234234
return []
235235
except UidInvalid:
236-
self.log.error( # noqa: G201
237-
("Got Uidvalidity error when searching. Skipping."),
238-
exc_info=True,
236+
self.log.exception(
237+
"Got Uidvalidity error when searching. Skipping."
239238
)
240239
return []
241240

inbox/sendmail/smtp/postel.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ def _connect(self, host, port): # type: ignore[no-untyped-def]
161161
self.connection.connect(host, port)
162162
except OSError as e:
163163
# 'Connection refused', SSL errors for non-TLS connections, etc.
164-
log.error( # noqa: G201
165-
"SMTP connection error", exc_info=True, server_error=e.strerror
166-
)
164+
log.exception("SMTP connection error")
167165
msg = _transform_ssl_error(e.strerror)
168166
raise SendMailException(msg, 503) # noqa: B904
169167

@@ -364,9 +362,7 @@ def _send(self, recipients, msg): # type: ignore[no-untyped-def]
364362
)
365363
except smtplib.SMTPException as err:
366364
last_error = err
367-
self.log.error( # noqa: G201
368-
"Error sending", error=err, exc_info=True
369-
)
365+
self.log.exception("Error sending")
370366

371367
assert last_error is not None
372368
self.log.error(

0 commit comments

Comments
 (0)