ไม่มีแอปรอด first contact กับ users จริง ตอนเริ่มใช้ จะเจอ errors
ดังนั้น production 部分 แอปส่วนใหญ่มีทาง track และ report errors ใช้ exception_notification แบบง่าย หรือ webapp อย่าง Honeybadger หรือ Raygun
แต่เร็วๆ นี้ จะเห็น exceptions เดิมซ้ำๆ หลายสิบครั้งต่อวัน Web service ที่พึ่งพาไม่เสถียร หรือ users typo email ทำให้ messages ส่งไม่ไป Exceptions ควร exceptional, unexpected แต error ไหน unexpected ได้ ถ้าเห็น 30 ครั้งต่อวัน?
มีวิธีแก้ดีกว่า report และ ignore มากมาย exceptions เยอะส่วนใหญ่ อยู่ใน categories พื้นฐาน และแต่ละ category ใช้ patterns ลด noise และทำ users שמח
The Network Is Down!
แอปน้อยทำงานคนเดียว ส่วนใหญ่ communicate กับแอปอื่น แตตอน geolocation API ล่ม หรือ ec2 hiccup ไมอยากได้ spam ด้วย thousands exceptions ที่ทำไมได้
ตอน deal กับ unreliable services ลอง Circuit Breaker pattern จาก Release It ของ Michael Nygard:
Idea หลักของ circuit breaker เรียบง่าย Wrap protected function call ใน circuit breaker object ที่ monitor failures ถ้า failures ถึง threshold circuit breaker trips และ calls ต่อไป return error ทันที โดยไม่ทำ protected call เลย
ตอน service ล่ม จะหยุดพยายาม connect อัตโนมัติ ทำงานต่อโดยไม่มี functionality นั้น สร้าง self-healing ได้ ให้ app check service อีกครั้งหลังเวลาผ่านไป
Circuit breaker pattern ออกแบบกัน cascading failures แตใช้ limit exception notifications ได้ ด้วย pattern นี้ ต้อง notified แค่ตอน trips และตอน recover ไม่ได้ สร้าง thousands exceptions กลายเป็น 몇個 ถ้ายังมาก ให้ breaker report แค่ตอน fail retries หลายครั้งติด (หรือหา service 可靠กว่า!)
ใช้ pattern นี้ต้องทำงาน แตทำ user experience ดีกว่า แทน hard error page จะเห็น message ว่าฟีเจอร์ทำงานไม่ได้ ลองใหม่ภายหลัง ข้อมูลดีกว่า ส่งในเวลาที่ถูกต้อง
Turns Out gmaaaail.com Isn't What You Meant
Exception อีกประเภทที่เห็นเยอะ มาจาก bad user data
เช่น สมัคร typo email "justinweiss@gmaill.com" แทน "justinweiss@gmail.com" อันแรก theoretically valid แต emails ทั้งหมด bounce และได้ notified จาก email provider
Notifications เหล่านี้แค่ noise
ใช้ two-sided approach Prevent bad data up-front และ disable feature + notify user ถ้าล้มเหลวภายหลัง
สำหรับ email ใช้ mailcheck-js gem spellcheck "gmail.com" "yahoo.com" ตอนสมัคร:
{% img img-responsive /images/posts/email-spellcheck.gif 477 451 Ooh, fancy. %}
แตถ้า email ยัง bounce ภายหลัง ปิด email ให้ user นั้น
ตอนปิด feature ให้ใคร ต้องบอกพวกเขาว่าปิด และแก้ยังไง Banner บน top ของ site ปกติดี "เราส่ง emails ไม่ได้ ปิดส่งไปแล้ว คลิกอัปเดต email เราจะเปิดกลับคืน"
ได้ better data และ user emails ไมแค่ไป void ดีกว่า errors ที่ ignore อยู่
404s และ RoutingErrors
คงอยากรู้ broken links หรือ assets บน site แตสิ่งเหล่านี้ไม่ควรอยู่ใน exception tracker
สำหรับ "half-expected errors" แบบนี้ batch รวมกัน จัดการครั้งเดียว ไม่ต้อง notified ตอนเกิด อยาก pull ไม่ใช่ push
RoutingErrors และ 404s จัดการได้กับ Google Webmaster Tools (แสดง pages ที่ Google รู้จัก throw 404s) หรือรัน link-checker check links บน site ใน pre-release process
Exceptions Should Be Actionable
Exception emails ควร rare มาก Noise มากใน error tracker จะบล็อกการเห็นและ fix real problems ทันที
ถ้า annoyed กว่า embarrassed กับ exceptions ที่เห็น คุณมี noise problem ใช้ patterns ที่นี่ ลด noise และให้ users better experience พร้อมกัน
พูดถึง noisy exception categories ที่เห็นบ่อย แตแน่ใจว่าไมครอบคลุมหมด Exceptions ไหนขุ่นคุณมากที่สุด? เข้า categories นี้ไหม? หรือ define category ใหม่? กันไม่ให้รบกวนหลายร้อยครั้งต่อวัน ยังไง?