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

Goのエラースタックトレースの歴史と今後

sonatard
April 22, 2024

 Goのエラースタックトレースの歴史と今後

sonatard

April 22, 2024
Tweet

More Decks by sonatard

Other Decks in Programming

Transcript

  1. 2 (PͷΤϥʔτϨʔεͷྺ࢙ w IUUQTHJUIVCDPNQLHFSSPSTϦϦʔε w ελοΫτϨʔεʹରԠ w FSSPSXSBQͷελϯμʔυʹͳΔ func main()

    { if err := errorsA1(); err != nil { fmt.Printf("main: %+v", errors.Cause(err)) } } func errorsA1() error { err := errors.New("not found") return errors.Wrap(err, "errorsA1") }
  2. 4 (PͷΤϥʔτϨʔεͷྺ࢙ w 1SPQPTBMͰFSSPSͷXSBQͷఏҊͱ࣮ݧ༻ͷYFSSPST͕ϦϦʔε w IUUQTQLHHPEFWHPMBOHPSHYYFSSPST w XͰΤϥʔΛϥοϓ w ΤϥʔτϨʔεʹରԠ

    func main() { if err := xerrorsA1(); err != nil { fmt.Printf("main: %+v", err) } } func xerrorsA1() error { err := xerrors.New("not found") return xerrors.Errorf(": %w", err) }
  3. 5 (PͷΤϥʔτϨʔεͷྺ࢙ w (PͷFSSPSTͰਖ਼ࣜʹXSBQʹରԠ w GNU&SSPSGͱXͰϥοϓ͢Δ YFSSPST͸FSSPST&SSPSGͱXͩͬͨ  w ͔͠͠ελοΫτϨʔεग़ྗ͸࠾༻͞Εͳ͔ͬͨ

    w IUUQTHJUIVCDPNHPMBOHHPJTTVFTJTTVFDPNNFOU w NFUIBOFϒϩά(PͷFSSPS͕ελοΫτϨʔεΛؚ·ͳ͍ཧ༝ w YFSSPSTͰ͸ɺελοΫτϨʔεग़ྗ͸ܧଓ func main() { if err := errorsA1(); err != nil { fmt.Printf("main: %+v", err) } } func errorsA1() error { err := errors.New("not found") return fmt.Errorf("invalid argument %w", err) }
  4. 6 (PͷΤϥʔτϨʔεͷྺ࢙ w QLHFSSPSTͷ(JU)VCϦϙδτϦ͕ΞʔΧΠϒ͞ΕΔ w Ҡߦઌͷఆ൪͕ݟ͔ͭΒͳ͍ঢ়ଶ͕࢝·Δ w ʹYFSSPTͷ&SSPSGɺ6OXSBQɺ"Tɺ*Tɺ͕EFQSFDBUFE w YFSSPSTͷ6OXSBQɺ"Tɺ*T͸(PͷFSSPSTQBDLBHFͰ୅ସͰ͖ΔͨΊෆཁʹͳͬͨ

    w FSSPSTQBDLBHFͷ&SSPSG͸τϨʔεػೳ͕ͳ͍ͨΊɺYFSSPSTͷ&SSPSGΛ୅ସͰ͖ͳ͍ ͨΊYFSPSSTͷҠߦ͕ഭΒΕΔঢ়گʹͳΔ w ʹYFSSPST&SSPSG͸EFQSFDBUFEղআ w /FXͱ&SSPSG͕ར༻Ͱ͖ΔͷͰɺYFSSPST͕ར༻Ͱ͖Δঢ়ଶʹͳͬͨ
  5. 7 (PͷΤϥʔτϨʔεͷྺ࢙ w (PͰFSSPST+PJOͱGNU&SSPSGͷෳ਺Τϥʔͷ8SBQαϙʔτ w YFSSPST&SSPSG͸ෳ਺ΤϥʔͷϥοϓΛαϙʔτ͍ͯ͠ͳ͍ͷͰɺඪ४ϥΠϒϥϦͱͷ ػೳ͕ࠩੜ·Εͯ͠·ͬͨ w FSSPST+PJO͸YFSSPSTͰ΋࢖͑Δ w

    ΤϥʔτϨʔε్͕੾ΕΔ໰୊͕͋Δ func main() { if err := errorsA1(); err != nil { fmt.Printf("main: %+v", err) } } func errorsA1() error { err := errors.New("not found") return fmt.Errorf("1: %w, 2: %w", err, err) } func errorsA1() error { err := errors.New("not found") return errors.Join(err, errors.New("invalid argument")) }
  6. 8 (PͷΤϥʔτϨʔεͷࠓޙ w (0%&#6(FSSTUBDLUSBDFؚ͕·Ε͍ͯΔͱ͖ʹFSSPSʹελοΫτϨʔ εΛؚΉఏҊ w IUUQTHJUIVCDPNHPMBOHHPJTTVFT w (P4VSWFZ w

    (Pͷ՝୊ͰτοϓλΠ 11% 11% 7% 6% 6% 8% The type system Tooling Missing or immature libraries / frameworks Differences from more familiar languages / ecosystems Error handling / stack traces Learning curve / best practices / docs (open-ended text response) What, if anything, is the biggest challenge you personally face using Go today?
  7. 9 (PͷΤϥʔτϨʔεͷࠓޙ w ࠓޙͲ͏ͳΔͷ͔ʁ w 4VSWFZͰ্ҐͳͷͰɺରԠ͞ΕΔ͜ͱΛظ଴͍ͨ͠ w ରԠ͢Δ·ͰͲ͏͢Ε͹͍͍ͷ͔ʁ w QLHFSSPST΍YFSSPSTͷ··଱͑Δ

    w ۃྗӈԟࠨԟ͠ͳ͍ w ϓϩμΫτͰ໰୊͕ى͖͍ͯͳ͍ͳΒɺযͬͯҠߦ͠ͳ͍ w (PνʔϜΛظ଴ͯ͠଴ͭ w ଞͷύοέʔδΛ࠾༻͢Δ w ໨త͕͋Ε͹ద੾ʹଞͷύοέʔδΛ࠾༻͢Δ w ʮνʔϜͱͯ͠ΞʔΧΠϒ͞ΕͨQBDLBHF͸ར༻͠ͳ͍ϧʔϧͳͷͰɺQLH FSSPST͔ΒͷҠߦઌΛ୳͢ʯ w ʮෳ਺ͷΤϥʔϥοϓΛ࢖͍͍ͨͷͰɺYFSSPST͔ΒͷҠߦઌΛ୳͢ʯ w ʮϥΠϒϥϦ"ͷ#ػೳΛ࢖͏͔ΒҠߦ͢Δʯ
  8. 10 (PͷΤϥʔτϨʔεͷࠓޙ w ଞͷύοέʔδΛ࠾༻͢Δ w IUUQTHJUIVCDPNDPDLSPBDIECFSSPST w ϦονͳػೳΛ࢖͍͍ͨ w ΤϥʔҎ֎ͷ෇Ճ৘ใΛ؅ཧ͍ͨ͠ͳͲ

    w IUUQTHJUIVCDPNHPFSSPSTFSSPST w YFSSPST͸࢖͍ͨ͘ͳ͍͕ɺඪ४ϥΠϒϥϦͷFSSPSTͱ͍ۙΠϯλʔϑΣʔεʹͨ͠ ͍ɺFSSPST+PJOͰΤϥʔτϨʔεʹ໰୊͕͋Δ w IUUQTDTPQFOTPVSDFHPPHMFHPYQLHTJUF NBTUFSJOUFSOBMEFSSPSTEFSSPSTHP PSIUUQTHJUIVCDPNFBSUICPVOELJEFSSPSY w EFGFSͰΤϥʔͷϥοϓΛ͍ͨ͠ w EFSSPST΍FSSPSY͸γϯϓϧͳϥΠϒϥϦͳͷͰɺࢀߟʹಠࣗͰ࣮૷͢Δͷ΋͓͢͢ Ί
  9. 11 (PͷΤϥʔτϨʔεͷࠓޙ w QLHFSSPST func main() { if err :=

    errorsA1(); err != nil { fmt.Printf("main: %+v", errors.Cause(err)) } } func errorsA1() error { err := errors.New("not found") return errors.Wrap(err, "errorsA1") }
  10. 12 (PͷΤϥʔτϨʔεͷࠓޙ w YFSSPST func main() { if err :=

    xerrorsA1(); err != nil { fmt.Printf("main: %+v", err) } } func xerrorsA1() error { err := xerrors.New("not found") return xerrors.Errorf(": %w", err) }
  11. 13 (PͷΤϥʔτϨʔεͷࠓޙ w DPDLSPBDIECFSSPST func main() { if err :=

    errorsA1(); err != nil { fmt.Printf("main: %+v", err) } } func errorsA1() error { err := errors.New("not found") return errors.Wrap(err, "errorsA1") }
  12. 14 (PͷΤϥʔτϨʔεͷࠓޙ w HPFSSPST func main() { if err :=

    goerrorsA1(); err != nil { fmt.Printf("main: %v", err.(*errors.Error).ErrorStack()) } } func goerrorsA1() error { err := errors.New("not found") return errors.Wrap(err, 1) }
  13. 15 (PͷΤϥʔτϨʔεͷࠓޙ w EFSSPST func main() { if err :=

    derrorsA1(); err != nil { var se *derrors.StackError errors.As(err, &se) fmt.Printf("main: %s", se.Stack) } } func derrorsA1() (err error) { defer derrors.WrapStack(&err, "error in A1") return errors.New("not found") }
  14. 16 (PͷΤϥʔτϨʔεͷࠓޙ w FSSPSY func main() { if err :=

    errorxA1(); err != nil { fmt.Printf("main: %v", err) } } func errorxA1() (err error) { defer errorx.Trace(&err) return errors.New("not found") }