Web Application Good Error Message (and Bad Error Message)

672ee2598bea695496f11022a9a9c4c8?s=47 moznion
July 01, 2017

Web Application Good Error Message (and Bad Error Message)

A slide of YAPC::Fukuoka Hakata 2017

672ee2598bea695496f11022a9a9c4c8?s=128

moznion

July 01, 2017
Tweet

Transcript

  1. Web Application Good Error Message (and Bad Error Message) @moznion

  2. @moznion

  3. Error Message

  4. Error Messageͱ͸? - Τϥʔ͕ى͖ͨ࣌ʹग़ͯ͘Δϝοηʔδ - (جຊతʹ) ਓ͕ؒಡΉ - ҟৗܥͷॲཧ -

    Τϥʔϝοηʔδ͕པΓ……
  5. Example { "code": "500", "message": "Internal Server Error" }

  6. Error Messageͷ༻్ - ঢ়گͷද໌ - τϥϒϧγϡʔςΟϯάͷख͕͔Γ - αʔϏεͷ݈߁౓ͷࢦඪ

  7. Error MessageपΓͷ໰୊ - Ͳ͏ॻ͚͹ྑ͍ͷ͔͍·͍ͪ…… - ޙखʹճΓ͕ͪ…… - ίετ͕……

  8. Error Messageͷಛੑ

  9. Error Messageͷ࣍ݩ

  10. Error Messageͷ࣍ݩ 1࣍ݩ: Τϥʔίʔυ (ࣝผࢠ) 2࣍ݩ: Τϥʔϝοηʔδ (ঢ়گ) 3࣍ݩ: ϦΧόϦɾ࠶ݱ৘ใ

    (ରॲɾղܾ)
  11. Error Messageͷ࣍ݩ 1࣍ݩ: Τϥʔίʔυ (ࣝผࢠ) 2࣍ݩ: Τϥʔϝοηʔδ (ঢ়گ) 3࣍ݩ: ϦΧόϦɾ࠶ݱ৘ใ

    (ରॲɾղܾ) ଞͷΤϥʔͱͷ۠ผ
  12. Error Messageͷ࣍ݩ 1࣍ݩ: Τϥʔίʔυ (ࣝผࢠ) 2࣍ݩ: Τϥʔϝοηʔδ (ঢ়گ) 3࣍ݩ: ϦΧόϦɾ࠶ݱ৘ใ

    (ରॲɾղܾ)
  13. Error Messageͷ࣍ݩ 1࣍ݩ: Τϥʔίʔυ (ࣝผࢠ) 2࣍ݩ: Τϥʔϝοηʔδ (ঢ়گ) 3࣍ݩ: ϦΧόϦɾ࠶ݱ৘ใ

    (ରॲɾղܾ) Կ͕ى͖͍ͯΔ͔ͷఏࣔ
  14. Error Messageͷ࣍ݩ 1࣍ݩ: Τϥʔίʔυ (ࣝผࢠ) 2࣍ݩ: Τϥʔϝοηʔδ (ঢ়گ) 3࣍ݩ: ϦΧόϦɾ࠶ݱ৘ใ

    (ରॲɾղܾ)
  15. Error Messageͷ࣍ݩ 1࣍ݩ: Τϥʔίʔυ (ࣝผࢠ) 2࣍ݩ: Τϥʔϝοηʔδ (ঢ়گ) 3࣍ݩ: ϦΧόϦɾ࠶ݱ৘ใ

    (ରॲɾղܾ) ໰୊ରॲɾղܾͷख๏ͷఏࣔ
  16. Error Messageͷํ޲ੑ

  17. Error Messageͷํ޲ੑ - ͳͥग़͢ͷ͔ - ԿΛग़͢ͷ͔ (࣍ݩʹؔΘΔ) - ͍ͭग़͢ͷ͔ (ϩάϨϕϧ)

    - Ͳ͜ʹग़͢ͷ͔ (ϩάऩूɼUI)
  18. Error Messageͷํ޲ੑ - ͳͥग़͢ͷ͔ - ԿΛग़͢ͷ͔ (࣍ݩʹؔΘΔ) - ͍ͭग़͢ͷ͔ (ϩάϨϕϧ)

    - Ͳ͜ʹग़͢ͷ͔ (ϩάऩूɼUI)
  19. Error Messageͷํ޲ੑ - ͳͥग़͢ͷ͔ - ԿΛग़͢ͷ͔ (࣍ݩʹؔΘΔ) - ͍ͭग़͢ͷ͔ (Ϩϕϧɼྔ)

    - Ͳ͜ʹग़͢ͷ͔ (ϩάऩूɼUI)
  20. Error Messageͷํ޲ੑ - ͳͥग़͢ͷ͔ - ԿΛग़͢ͷ͔ (࣍ݩʹؔΘΔ) - ͍ͭग़͢ͷ͔ (Ϩϕϧɼྔ)

    - Ͳ͜ʹ (୭ʹ) ग़͢ͷ͔ (ϩάऩूɼUI)
  21. Error Messageͷ ϥΠϑαΠΫϧ

  22. - ୹ण໋ - ͦͷ৔Ͱͷରॲʹར༻ - ଈԠ - ௕ण໋ - ࠜຊతͳղܾʹར༻

    - ϝτϦΫεతʹ΋ - ͋ͱͰݕࡧͰ͖Δ Error MessageͷϥΠϑαΠΫϧ
  23. - ୹ण໋ - ͦͷ৔Ͱͷରॲʹར༻ - ଈԠ - ௕ण໋ - ࠜຊతͳղܾʹར༻

    - ϩάɾϝτϦΫεత - ͋ͱͰݕࡧͰ͖Δ Error MessageͷϥΠϑαΠΫϧ
  24. - ୹ण໋ - ͦͷ৔Ͱͷରॲʹར༻ - ଈԠ - ௕ण໋ - ࠜຊతͳղܾʹར༻

    - ϩάɾϝτϦΫεత - ͋ͱͰݕࡧͰ͖Δ Error MessageͷϥΠϑαΠΫϧ
  25. - ୹ण໋ - ͦͷ৔Ͱͷରॲʹར༻ - ଈԠ - ௕ण໋ - ࠜຊతͳղܾʹར༻

    - ϩάɾϝτϦΫεత - ͋ͱͰݕࡧͰ͖Δ Error MessageͷϥΠϑαΠΫϧ Errorͷྲྀ଎Λ ؂ࢹͯ͠alertͱ͔
  26. Good Error Message

  27. ྑ͍Error Messageͱ͸? - Կ͕ى͖͍ͯΔ͔෼͔Δ (ඞਢ) - ؆ܿͰ͋Δ͜ͱ (޷·͍͠) - ରॲखஈ͕ఏҊ͞Ε͍ͯΔ͜ͱ

    (࠷ߴ) - ղܾखஈ͕ఏҊ͞Ε͍ͯΔ͜ͱ (࠷ߴ)
  28. ྑ͍Error Messageͱ͸? - Կ͕ى͖͍ͯΔ͔෼͔Δ (ඞਢ) - ؆ܿͰ͋Δ͜ͱ (޷·͍͠) - ରॲखஈ͕ఏҊ͞Ε͍ͯΔ͜ͱ

    (࠷ߴ) - ղܾखஈ͕ఏҊ͞Ε͍ͯΔ͜ͱ (࠷ߴ)
  29. "ରॲ"ͱ"ղܾ"ͷҧ͍

  30. ղܾ͢ΔͨΊͷError Message - ࠜຊతͳमਖ਼ͷॿ͚ʹͳΔϝοηʔδ - e.g. RDBMS͕ग़͢ϝοηʔδ - ։ൃऀ޲͚ -

    ௕໋ϥΠϑαΠΫϧ
  31. ରॲ͢ΔͨΊͷError Message - ͦͷ৔Ͱൃੜ͍ͯ͠Δ໰୊Λଧ౗͢Δ - e.g. ʮωοτϫʔΫྑ͍ͱ͜ΖͰࢼͯ͠ʂʯ - ղܾʹܨ͕Δ৔߹΋͋Δ -

    ར༻ऀ͕ετϨεແ͘ιϑτ΢ΣΞΛར༻͢Δ ͨΊͷखॿ͚ => Ϣʔβମݧ - ։ൃऀɾར༻ऀ૒ํ޲͚ - ୹໋ϥΠϑαΠΫϧ
  32. ྑ͍Error Messageͱ͸? - Կ͕ى͖͍ͯΔ͔෼͔Δ (ඞਢ) - ؆ܿͰ͋Δ͜ͱ (޷·͍͠) - ରॲखஈ͕ఏҊ͞Ε͍ͯΔ͜ͱ

    (࠷ߴ) - ղܾखஈ͕ఏҊ͞Ε͍ͯΔ͜ͱ (࠷ߴ)
  33. Bad Error Message

  34. ѱ͍Error Messageͱ͸ - ·ͬͨ͘ঢ়گ͕Θ͔Βͳ͍ - e.g. "Something wrong!" - Ͳ͏͢Ε͹ྑ͍ͱ͍͏ͷͩ……

    - e.g. "Invalid parameter", "Query is too big" - ৘ใྔ͕ଟ͗͢Δ - ੌ·͍͡ྔͷstack trace͕ग़Δͱ͔…… - ΫϦεϚεπϦʔݱ৅
  35. ਅͷѱ͍Error Message

  36. ਅͷѱ͍Error Message Error Message͕ແ͍

  37. ਅͷѱ͍Error Message Error Message͕ແ͍ ແ͍ΑΓ͸͋ͬͨํ͕ྑ͍

  38. ࣄྫ

  39. Client Side

  40. HTTP Status Code - 1xx, 2xx, 3xx, 4xx, 5xx -

    ίʔυʹΑΔ1࣍ݩ৘ใ - (↑ͱ͍͏ͷ͸ਖ਼͘͠ͳ͍ɽHTTP Status Codeʹ͸ηϚϯςΟΫε͕͋Δ)
  41. - Over HTTPͳrequestͷerror response - e.g. 
 {
 "code": 1212,


    "error": "Not permitted operation"
 } API Response
  42. ؅ཧը໘্ͷදࣔ - ؅ཧը໘ͷૢ࡞தʹΤϥʔ͕ى͖Δ - ओʹΦϖϨʔλͷਓ޲͚Έ͍ͨͳ৔߹

  43. ؅ཧը໘্ͷදࣔ - ؅ཧը໘ͷૢ࡞தʹΤϥʔ͕ى͖Δ - ओʹΦϖϨʔλͷਓ޲͚Έ͍ͨͳ৔߹

  44. ؅ཧը໘্ͷදࣔ - ؅ཧը໘ͷૢ࡞தʹΤϥʔ͕ى͖Δ - ओʹΦϖϨʔλͷਓ޲͚Έ͍ͨͳ৔߹ ଐਓੑͩ... (ٞ࿦͠·ͤΜ)

  45. Facebook Graph API - APIͷΦʔϓϯϓϥοτϑΥʔϜ - fbtrace_idʹΑΔΤϥʔ৘ใͷఏࣔ& τϥοΩϯά

  46. Server Side

  47. Exit status - `$ echo $?` - 0ͩͬͨΒ੒ޭ - ͦͷଞ͸ࣦഊ

    (ਈ࢜ڠఆ) - http://moznion.hatenadiary.com/ entry/2017/06/30/181433
  48. ୯७ͳError Log [12:29:14] DBI Exception: DBD::mysql::st execute failed: Duplicate entry

    'XXXXXXXXXXXXXX' for key 'user' [for Statement "INSERT /* ./local/lib/perl5/ Try/Tiny.pm line 77 */ INTO user (id) VALUES (?)" with ParamValues: 0="XXXXXXXXXXXXXX"] at ./lib/MyApp/Infra/ UserRepository/.pm line 123
  49. GitͷError Message $ git push origin test To github.com:moznion/sandbox.git !

    [rejected] test -> test (non-fast-forward) error: failed to push some refs to 'git@github.com:moznion/ sandbox.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  50. ·ͱΊ

  51. ྑ͍Error Messageͱ͸? - Կ͕ى͖͍ͯΔ͔෼͔Δ (ඞਢ) - ؆ܿͰ͋Δ͜ͱ (޷·͍͠) - ରॲखஈ͕ఏҊ͞Ε͍ͯΔ͜ͱ

    (࠷ߴ) - ղܾखஈ͕ఏҊ͞Ε͍ͯΔ͜ͱ (࠷ߴ)
  52. ྑ͍Error MessageΛॻ͘ʹ͸ - ͳΔ΂࣍͘ݩͷߴ͍৘ใΛࣔ͢ - ݟͨਓ͕ٽ͔ͳ͍Α͏ʹ - ໨తΛ໌֬ʹɼͳΔ΂͘؆ܿʹ - ୭͕ݟΔͷ͔ɼԿʹ࢖ΘΕΔͷ͔

    - ͱ͸͍͑ग़͠ौΒͳ͍
  53. ͱ͸͍͑ - ৗʹ࣍ݩͷߴ͍ΤϥʔϝοηʔδΛॻ͘ ͷ͸೉͍͠ - ίετͷ݉Ͷ߹͍ - ݁ہϏδωευϝΠϯΛॻ͔ͳ͍ͱ
 Ͳ͏͠Α͏΋ͳ͍ͷͰ……

  54. ίετײͱ໨త - ৄࡉͳΤϥʔϝοηʔδ͕ग़͢ͱ
 ϖΠͰ͖Δ෦෼͸खް͘ॻ͘ - ͦ͏͡Όͳ͍ͱ͜Ζ͸ͦΕͳΓʹ
 (ͱ͸͍͑ঢ়گ͘Β͍͸ͪΌΜͱॻ͘) - ྟػԠมʹ΍͍ͬͯ͘

  55. Q?

  56. Misc

  57. Error Message຋༁

  58. Error Message຋༁ - ҃ΔΤϥʔΛʮड͚औΓଆʯʹ;͞Θ͍͠ ಺༰ʹม׵͢Δ - e.g. αʔό಺෦Ͱൃੜͨ͠ΤϥʔΛ
 Ϣʔβʹࣔ͢৔߹ -

    e.g. ଞͷαʔϏε͔Βड͚औͬͨ
 ΤϥʔΛࣗ෼ͷจ຺ʹม׵͢Δ৔߹
  59. Error Message຋༁ - "SQL Error" => "500 αʔϏεʹ໰୊͕ੜ͡ ͍ͯ·͢" -

    status 5963 => "૬खͷαʔό͕Ωϟύγ ςΟΦʔόͰࢮΜͰΔʂʂ" - status code͔Βঢ়گͷจݴʹى͜͢ͳͲ ͱ͍ͬͨ࣍ݩͷΞηϯγϣϯ΋ى͖͕ͪ
  60. Stack TraceΛ
 Client޲͚Error Message ʹಥͬࠐΉ

  61. Client΁ͷError Messageͱͯ͠ Stack traceΛಥͬࠐΉ - ։ൃ࣌ͷςΫχοΫ (ςΫχοΫ?) - αʔό͕ྫ֎Λ্͛ͨ࣌ͷελοΫτϨʔ εΛbodyʹ٧Ίͯ500Λฦ͢

  62. Client΁ͷError Messageͱͯ͠ Stack traceΛಥͬࠐΉ - Client։ൃऀʮͳΜ͔͓͔͍͠ΜͰ͚͢ ͲʙʯΈ͍ͨͳ࣌ʹελοΫτϨʔεΛ
 ͦͷ··౉ͯ͠΋Β͑ΔͷͰศར - ProductionͰdisableʹ͠๨ΕΔͱ͠͵

  63. Q?