Be concious of how exceptions will be read wrt newlines

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the exceptions category.

Last Updated: 2024-11-23

I received this email from Oxbridge Notes after invoice payments failed (formatting SHOULD look cramped BTW)

PayMonthlyCommissionsService generated all the invoices but failed to pay some of them. Failed invoices: 2020-6-8, 2020-6-9, 2020-6-10, 2020-6-13. Paid invoices: 2020-6-1, 2020-6-2, 2020-6-3, 2020-6-4, 2020-6-5, 2020-6-6, 2020-6-7, 2020-6-11, 2020-6-12, 2020-6-14, 2020-6-15, 2020-6-16, 2020-6-17, 2020-6-18, 2020-6-19, 2020-6-20, 2020-6-21, 2020-6-22, 2020-6-23, 2020-6-24, 2020-6-25, 2020-6-26, 2020-6-27, 2020-6-28, 2020-6-29, 2020-6-30, 2020-6-31, 2020-6-32, 2020-6-33, 2020-6-34, 2020-6-35, 2020-6-36, 2020-6-37Failed errors: someone@gmail.com:, someone1@hotmail.com: , someone2@hotmail.com: , someone4@hotmail.co.uk: . PLEASE DOUBLE CHECK PAYPAL BEFORE PAYING AGAIN

This was cramped onto one massive line and almost impossible to parse. It needed newlines.

I fixed the error message generator to be like this:

message =
  'PayMonthlyCommissionsService generated all the invoices but failed to pay some of ' \
  "them. \n Failed invoices: #{failed.join(', ')}. \n Paid invoices: #{successful.join(', ')}" \
  "Failed errors: #{failed_errors.join(', ')}. \n\n PLEASE DOUBLE CHECK PAYPAL BEFORE PAYING AGAIN"

Lesson

Don't forget to include newlines in your (more involved) exception messages.