My Blog

My WordPress Blog

My Blog

My WordPress Blog

Errors astype In Go 1 26 Makes Error Handling Better

In this video, we will look at how Go 1.26 silently improved the error inspection with the new errors.AsType function. If you’re interested in the new changes of the Cause function in Go 1.26, feel free to check out this video: https://youtu.be/Jv2fjkz24e8. . . πŸ“ Description. Stop patching runtime panics that your compiler could have caught. A focused but impactful addition landing in Go 1.26 finally gives error inspection the type-safety it always deserved. In this quick, practical tutorial, we dig into Go’s source code and real examples to show exactly why `errors.As` has always been a footgun, how the new `errors.AsType` generic function eliminates that risk at compile time, and what this means for how you write error handling going forward. By the end, you will know precisely when to reach for `errors.Is`, `errors.As`, or the new `errors.AsType` and why.. β€’ Understand the core problem with `errors.As` in Go 1.25 and earlier: its reliance on reflection, the pre-declared typed nil pointer boilerplate, and why type mismatches silently panic at runtime instead of failing at compile time. β€’ See how Go 1.26’s `errors.AsType` leverages generics to express the target type as a type parameter, returning the typed value and a boolean directly without any pointer indirection required. β€’ Walk through a concrete before-and-after example using `*fs.PathError` and `*json.SyntaxError` to see exactly how the call site becomes cleaner and safer. β€’ Understand why pointer types like `*fs.PathError` are needed rather than value types, and how pointer receivers on the `Error()` method drive that decision. β€’ Get a clear mental model for choosing between `errors.Is`, `errors.As`, and `errors.AsType` so you always pick the right tool for the job. . . ⏳ Timestamps:. 00:00 – Introduction. 00:16 – The Problem. 01:08 – Use Case. 10:10 – Outro. . . πŸ”— Links:. [1] https://pkg.go.dev/errors#AsType. . . πŸ‘‹ Hey there!. If you are new to this channel: Hey πŸ‘‹ my name is Flo and I am a professional software engineer with a passion for coding in Golang, TypeScript, JavaScript, and Rust. This channel is where I share that passion and dive into the exciting world of software engineering.. . . πŸ“¨ Support and Connect!. Become a member. https://www.youtube.com/@FloWoelki/membership. Discord: https://discord.gg/TnA7drJ. X / Twitter: https://x.com/FlorianWoelki. LinkedIn: https://www.linkedin.com/in/florian-woelki/. GitHub: https://github.com/FlorianWoelki. . . πŸ“ Copyright Notice. The original Go Gopher was designed by RenΓ©e French (Source: https://go.dev/blog/gopher License details: https://creativecommons.org/licenses/by/4.0/). The gopher appearing in this video and thumbnail has been modified from the original design and is based on an illustration from Maria Letta’s free-gophers-pack (Source: https://github.com/MariaLetta/free-gophers-pack License: CC0 1.0 Public Domain https://creativecommons.org/publicdomain/zero/1.0/).. . . #go #astype #errors

Errors astype In Go 1 26 Makes Error Handling Better

Errors astype In Go 1 26 Makes Error Handling Better

Golang 1 26 Changed How I Write Go Performance Generics Error Handling

5 Levels Of Go Error Handling

Handling Errors Like A 10x Engineer In Golang Golang Service Pattern

Go 1 26 Quietly Improved Fmt errorf Here s How

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top