Skip to content

Commit 3ee26d4

Browse files
committed
fix(worker): read payments from new payments.json + log full traceback
Two fixes: 1. Discord moved payments out of user.json into Account/user_data_exports/discord_billing/payments.json sometime in 2025. Read from the new location when present; fall back to the old user_json['payments'] field for older exports. 2. The exception handler in process_package was 'print(e)', which only logs the exception's str() — useless for debugging. Always log the full traceback to CloudWatch before swallowing into the DB.
1 parent ab76fa0 commit 3ee26d4

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

src/tasks.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,20 @@ def read_analytics_file(package_status_id, package_id, link, session):
227227
'avatar_url': generate_avatar_url_from_user_id_avatar_hash(relation_ship['id'], relation_ship['user']['avatar']),
228228
'display_name': 'display_name' in relation_ship and relation_ship['display_name'] or None,
229229
})
230-
for payment in user_json['payments']:
230+
# Discord moved payments out of user.json into a separate file
231+
# (Account/user_data_exports/discord_billing/payments.json) sometime
232+
# in 2025. Read the new location if present, otherwise fall back to
233+
# the legacy field for older exports.
234+
payment_records = []
235+
user_root = user_path.rsplit('/', 1)[0]
236+
new_payments_path = f'{user_root}/user_data_exports/discord_billing/payments.json'
237+
if new_payments_path in zip.namelist():
238+
with zip.open(new_payments_path) as f:
239+
payment_records = orjson.loads(f.read()).get('records', [])
240+
else:
241+
payment_records = user_json.get('payments', [])
242+
243+
for payment in payment_records:
231244
payments.append({
232245
'id': payment['id'],
233246
'amount': payment['amount'],
@@ -928,13 +941,18 @@ def process_package(package_status_id, package_id, link, worker_name='regular_pr
928941
download_file(package_status_id, package_id, link, session)
929942
read_analytics_file(package_status_id, package_id, link, session)
930943
except Exception as e:
931-
print(e)
944+
# Always log the full trace to CloudWatch — print(e) alone gives just
945+
# the exception message and no line numbers, which makes the failure
946+
# impossible to debug from logs.
947+
tb = ''.join(traceback.format_exception(type(e), e, e.__traceback__))
948+
print(f'process_package failed for {package_id}:\n{tb}')
949+
932950
expected = ('EXPIRED_LINK')
933951
current = str(e)
934952
e_traceback = None
935953
if expected not in current:
936954
current = 'UNKNOWN_ERROR'
937-
e_traceback = ''.join(traceback.format_exception(type(e), e, e.__traceback__))
955+
e_traceback = tb
938956
session.query(PackageProcessStatus).filter(PackageProcessStatus.id == package_status_id).update({
939957
'is_errored': True,
940958
'error_message_code': current,

0 commit comments

Comments
 (0)