Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web Application Good Error Message (and Bad Error Message)

moznion
July 01, 2017

Web Application Good Error Message (and Bad Error Message)

A slide of YAPC::Fukuoka Hakata 2017

moznion

July 01, 2017
Tweet

More Decks by moznion

Other Decks in Technology

Transcript

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

    View full-size slide

  2. Error Message

    View full-size slide

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

    View full-size slide

  4. Example
    {
    "code": "500",
    "message": "Internal Server Error"
    }

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  7. Error Messageͷಛੑ

    View full-size slide

  8. Error Messageͷ࣍ݩ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  15. Error Messageͷํ޲ੑ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  20. Error Messageͷ
    ϥΠϑαΠΫϧ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  25. Good Error Message

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  28. "ରॲ"ͱ"ղܾ"ͷҧ͍

    View full-size slide

  29. ղܾ͢ΔͨΊͷError Message
    - ࠜຊతͳमਖ਼ͷॿ͚ʹͳΔϝοηʔδ
    - e.g. RDBMS͕ग़͢ϝοηʔδ
    - ։ൃऀ޲͚
    - ௕໋ϥΠϑαΠΫϧ

    View full-size slide

  30. ରॲ͢ΔͨΊͷError Message
    - ͦͷ৔Ͱൃੜ͍ͯ͠Δ໰୊Λଧ౗͢Δ
    - e.g. ʮωοτϫʔΫྑ͍ͱ͜ΖͰࢼͯ͠ʂʯ
    - ղܾʹܨ͕Δ৔߹΋͋Δ
    - ར༻ऀ͕ετϨεແ͘ιϑτ΢ΣΞΛར༻͢Δ
    ͨΊͷखॿ͚ => Ϣʔβମݧ
    - ։ൃऀɾར༻ऀ૒ํ޲͚
    - ୹໋ϥΠϑαΠΫϧ

    View full-size slide

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

    View full-size slide

  32. Bad Error Message

    View full-size slide

  33. ѱ͍Error Messageͱ͸
    - ·ͬͨ͘ঢ়گ͕Θ͔Βͳ͍
    - e.g. "Something wrong!"
    - Ͳ͏͢Ε͹ྑ͍ͱ͍͏ͷͩ……
    - e.g. "Invalid parameter", "Query is too big"
    - ৘ใྔ͕ଟ͗͢Δ
    - ੌ·͍͡ྔͷstack trace͕ग़Δͱ͔……
    - ΫϦεϚεπϦʔݱ৅

    View full-size slide

  34. ਅͷѱ͍Error Message

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  37. HTTP Status Code
    - 1xx, 2xx, 3xx, 4xx, 5xx
    - ίʔυʹΑΔ1࣍ݩ৘ใ
    - (↑ͱ͍͏ͷ͸ਖ਼͘͠ͳ͍ɽHTTP Status
    Codeʹ͸ηϚϯςΟΫε͕͋Δ)

    View full-size slide

  38. - Over HTTPͳrequestͷerror response
    - e.g. 

    {

    "code": 1212,

    "error": "Not permitted operation"

    }
    API Response

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  43. Exit status
    - `$ echo $?`
    - 0ͩͬͨΒ੒ޭ
    - ͦͷଞ͸ࣦഊ (ਈ࢜ڠఆ)
    - http://moznion.hatenadiary.com/
    entry/2017/06/30/181433

    View full-size slide

  44. ୯७ͳ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

    View full-size slide

  45. 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 '[email protected]: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.

    View full-size slide

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

    View full-size slide

  47. ྑ͍Error MessageΛॻ͘ʹ͸
    - ͳΔ΂࣍͘ݩͷߴ͍৘ใΛࣔ͢
    - ݟͨਓ͕ٽ͔ͳ͍Α͏ʹ
    - ໨తΛ໌֬ʹɼͳΔ΂͘؆ܿʹ
    - ୭͕ݟΔͷ͔ɼԿʹ࢖ΘΕΔͷ͔
    - ͱ͸͍͑ग़͠ौΒͳ͍

    View full-size slide

  48. ͱ͸͍͑
    - ৗʹ࣍ݩͷߴ͍ΤϥʔϝοηʔδΛॻ͘
    ͷ͸೉͍͠
    - ίετͷ݉Ͷ߹͍
    - ݁ہϏδωευϝΠϯΛॻ͔ͳ͍ͱ

    Ͳ͏͠Α͏΋ͳ͍ͷͰ……

    View full-size slide

  49. ίετײͱ໨త
    - ৄࡉͳΤϥʔϝοηʔδ͕ग़͢ͱ

    ϖΠͰ͖Δ෦෼͸खް͘ॻ͘
    - ͦ͏͡Όͳ͍ͱ͜Ζ͸ͦΕͳΓʹ

    (ͱ͸͍͑ঢ়گ͘Β͍͸ͪΌΜͱॻ͘)
    - ྟػԠมʹ΍͍ͬͯ͘

    View full-size slide

  50. Error Message຋༁

    View full-size slide

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

    Ϣʔβʹࣔ͢৔߹
    - e.g. ଞͷαʔϏε͔Βड͚औͬͨ

    ΤϥʔΛࣗ෼ͷจ຺ʹม׵͢Δ৔߹

    View full-size slide

  52. Error Message຋༁
    - "SQL Error" => "500 αʔϏεʹ໰୊͕ੜ͡
    ͍ͯ·͢"
    - status 5963 => "૬खͷαʔό͕Ωϟύγ
    ςΟΦʔόͰࢮΜͰΔʂʂ"
    - status code͔Βঢ়گͷจݴʹى͜͢ͳͲ
    ͱ͍ͬͨ࣍ݩͷΞηϯγϣϯ΋ى͖͕ͪ

    View full-size slide

  53. Stack TraceΛ

    Client޲͚Error Message
    ʹಥͬࠐΉ

    View full-size slide

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

    View full-size slide

  55. Client΁ͷError Messageͱͯ͠
    Stack traceΛಥͬࠐΉ
    - Client։ൃऀʮͳΜ͔͓͔͍͠ΜͰ͚͢
    ͲʙʯΈ͍ͨͳ࣌ʹελοΫτϨʔεΛ

    ͦͷ··౉ͯ͠΋Β͑ΔͷͰศར
    - ProductionͰdisableʹ͠๨ΕΔͱ͠͵

    View full-size slide