{"id":472,"date":"2026-06-04T09:00:00","date_gmt":"2026-06-04T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/"},"modified":"2026-06-04T09:00:00","modified_gmt":"2026-06-04T03:30:00","slug":"go-error-wrapping-guide","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/","title":{"rendered":"Go Error Wrapping with errors.Is and errors.As"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go error wrapping lets you add context to an error without losing the original cause. In this post, you will learn how <code>%w<\/code>, <code>errors.Is<\/code>, <code>errors.As<\/code> and <code>errors.Join<\/code> work together. Then we will run one program that shows each tool in action.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This lesson builds on <a href=\"https:\/\/smitabharat.com\/blog\/go-error-handling-guide\/\">Go error handling for beginners<\/a> and <a href=\"https:\/\/smitabharat.com\/blog\/go-interfaces-examples\/\">Go interfaces<\/a>. We also use ideas from <a href=\"https:\/\/smitabharat.com\/blog\/go-structs-beginners-guide\/\">Go structs<\/a> and <a href=\"https:\/\/smitabharat.com\/blog\/go-file-handling-examples\/\">Go file handling<\/a>. So it helps to read those first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Go Error Wrapping?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An error in Go is a value. When a low level function fails, it returns an error. Then the caller often adds a note and passes the error up. Wrapping means that the new error keeps the old one inside it, much like a letter inside an envelope.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a courier who finds a locked door. So he writes a new slip that says the delivery failed. Then he attaches the old slip that says the door was locked. Both messages travel together. In the same way, Go error wrapping keeps the full story from the deep cause to the top message.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You wrap an error with <code>fmt.Errorf<\/code> and the <code>%w<\/code> verb. Later, you can look inside the wrapper and ask what the real cause was. That is the whole idea of Go error wrapping.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Error Wrapping Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Plain errors lose information while they travel up. When every layer just returns the error, the final message may say &#8220;not found&#8221; with no clue where. If every layer creates a new text error, the original cause is gone. Here is what Go error wrapping gives you.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Clear messages<\/strong>: each layer adds where and why, such as <code>loadProfile(7)<\/code>.<\/li>\n\n\n\n<li><strong>Safe checks<\/strong>: the caller can still test for the original error.<\/li>\n\n\n\n<li><strong>Better logs<\/strong>: one line tells the whole story from top to bottom.<\/li>\n\n\n\n<li><strong>Cleaner decisions<\/strong>: code can react to a type of failure, not to message text.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">However, matching on text is fragile. A small wording change breaks the check. Therefore, Go gives you <code>errors.Is<\/code> and <code>errors.As<\/code> to test errors by identity and by type.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Error Wrapping Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every wrapped error has a pointer to the error inside it. Because of this pointer, the errors form a chain. Go provides tools to walk that chain, and Go error wrapping depends on them.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-1-1024x640.png\" alt=\"Go Error Wrapping diagram showing loadProfile wrapping the findUser error that holds ErrNotFound\" class=\"wp-image-439\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">loadProfile wraps the error from findUser with the percent w verb. The chain keeps ErrNotFound inside, so errors.Is can still find it from the top.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Wrapping with the %w Verb<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A call such as <code>fmt.Errorf(\"loadProfile(%d): %w\", id, err)<\/code> builds a new error. Its text includes your note and the original message. Also, its chain keeps the original error. When you use <code>%v<\/code> instead of <code>%w<\/code>, the text looks the same, but the chain is gone.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Checking Identity with errors.Is<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With <code>errors.Is(err, target)<\/code>, Go walks the chain and asks if any link equals the target. It works with sentinel errors, which are fixed values such as <code>ErrNotFound<\/code> or <code>fs.ErrNotExist<\/code>. Meanwhile, a plain <code>==<\/code> check fails once the error is wrapped.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Checking Type with errors.As<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With <code>errors.As(err, &amp;target)<\/code>, Go also walks the chain, but it looks for a link of a given type. When it finds one, it sets your variable to that value. As a result, you can read extra fields, such as which input was invalid.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Combining Errors with errors.Join<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes two things fail at once. In that case, <code>errors.Join<\/code> merges several errors into one. Its text shows each message on its own line, and <code>errors.Is<\/code> can still match any of them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Error Wrapping: Is vs As vs ==<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The three checks look alike, so people often mix them up. The table below shows when to use each one.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Check<\/th><th>Question it answers<\/th><th>Sees through wrapping?<\/th><th>Use for<\/th><\/tr><\/thead><tbody><tr><td>err == target<\/td><td>Is this exactly the same value?<\/td><td>No<\/td><td>Unwrapped errors only<\/td><\/tr><tr><td>errors.Is<\/td><td>Does the chain contain this value?<\/td><td>Yes<\/td><td>Sentinel errors like ErrNotFound<\/td><\/tr><tr><td>errors.As<\/td><td>Does the chain contain this type?<\/td><td>Yes<\/td><td>Custom error types with fields<\/td><\/tr><tr><td>errors.Unwrap<\/td><td>What is the next link?<\/td><td>One step<\/td><td>Rare, manual walking<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-2-1024x640.png\" alt=\"Go Error Wrapping diagram showing the results of equals, errors.Is and errors.As on a wrapped error\" class=\"wp-image-440\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Three checks on a wrapped error. Equals fails, errors.Is succeeds on the value, and errors.As succeeds on the type and fills a variable.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So in daily code, you will almost always reach for <code>errors.Is<\/code> and <code>errors.As<\/code>. Plain equality only works when no one has wrapped the error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Choosing the Right Verb and Helper<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go error wrapping gives you a few choices when you create an error. The table below shows which one fits each need.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>You want to<\/th><th>Use<\/th><th>Chain kept?<\/th><\/tr><\/thead><tbody><tr><td>Create a new base error<\/td><td>errors.New(&#8220;text&#8221;)<\/td><td>Not applicable<\/td><\/tr><tr><td>Add context and keep the cause<\/td><td>fmt.Errorf with %w<\/td><td>Yes<\/td><\/tr><tr><td>Add context and hide the cause<\/td><td>fmt.Errorf with %v<\/td><td>No<\/td><\/tr><tr><td>Report several failures together<\/td><td>errors.Join(a, b)<\/td><td>Yes, for each one<\/td><\/tr><tr><td>Attach rich data<\/td><td>A custom type with Error()<\/td><td>Yes, when it wraps<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Hiding the cause sounds odd, yet it has a use. Suppose your package calls a database library. If you wrap its error with <code>%w<\/code>, callers may start to depend on that library. Later, you cannot switch it without breaking them. So for an internal detail, return your own error and use <code>%v<\/code> for the text. For a stable cause, such as a missing file, use <code>%w<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Giving a Custom Type Its Own Unwrap<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A custom error type can also hold another error inside it. In that case, add a method named <code>Unwrap<\/code> that returns the inner error. After that, <code>errors.Is<\/code> and <code>errors.As<\/code> walk through your type as well. This is useful when you want both extra fields and a visible cause.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Error Wrapping Hands-On: One Program<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s see everything in one file. We make a sentinel error, a custom error type and two functions that wrap errors.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Define and Wrap the Errors<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First, <code>ErrNotFound<\/code> is a sentinel value. Next, <code>ValidationError<\/code> is a type with a field name and a message. The function <code>findUser<\/code> returns one of them, and <code>loadProfile<\/code> wraps whatever it gets.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var ErrNotFound = errors.New(\"user not found\")\n\ntype ValidationError struct {\n\tField string\n\tMsg   string\n}\n\nfunc (e *ValidationError) Error() string { return e.Field + \": \" + e.Msg }\n\nfunc findUser(id int) error {\n\tif id == 0 {\n\t\treturn &amp;ValidationError{Field: \"id\", Msg: \"must be positive\"}\n\t}\n\treturn ErrNotFound\n}\n\nfunc loadProfile(id int) error {\n\tif err := findUser(id); err != nil {\n\t\treturn fmt.Errorf(\"loadProfile(%d): %w\", id, err)\n\t}\n\treturn nil\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s look at the key lines. The method on <code>*ValidationError<\/code> makes it satisfy the <code>error<\/code> interface. In <code>loadProfile<\/code>, the <code>%w<\/code> verb adds the call name and the argument, but it keeps the cause inside. Finally, the pointer receiver means we compare and extract by pointer type.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Check the Errors<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Then we run the checks. We start with <code>errors.Is<\/code> and <code>==<\/code> on the same wrapped error. After that, we use <code>errors.As<\/code> on a validation failure, unwrap once, test a standard library error and join two errors.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func main() {\n\terr := loadProfile(7)\n\tfmt.Println(\"error text:\", err)\n\tfmt.Println(\"is ErrNotFound:\", errors.Is(err, ErrNotFound))\n\tfmt.Println(\"== compare:\", err == ErrNotFound)\n\n\terr = loadProfile(0)\n\tvar ve *ValidationError\n\tif errors.As(err, &amp;ve) {\n\t\tfmt.Println(\"validation field:\", ve.Field)\n\t}\n\tfmt.Println(\"unwrap once:\", errors.Unwrap(err))\n\n\t_, err = os.Open(\"\/no\/such\/file.txt\")\n\tfmt.Println(\"is fs.ErrNotExist:\", errors.Is(err, fs.ErrNotExist))\n\n\tjoined := errors.Join(errors.New(\"db failed\"), errors.New(\"cache failed\"))\n\tfmt.Println(\"joined:\")\n\tfmt.Println(joined)\n\tfmt.Println(\"with the verb v the chain is lost:\", errors.Is(fmt.Errorf(\"x: %v\", ErrNotFound), ErrNotFound))\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the real output from our run.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>error text: loadProfile(7): user not found\nis ErrNotFound: true\n== compare: false\nvalidation field: id\nunwrap once: id: must be positive\nis fs.ErrNotExist: true\njoined:\ndb failed\ncache failed\nwith the verb v the chain is lost: false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see, the wrapped error prints a helpful message, and <code>errors.Is<\/code> still finds <code>ErrNotFound<\/code>. The plain <code>==<\/code> check says false, because the value on top is the wrapper. Then the type check read the field <code>id<\/code>. Also, <code>os.Open<\/code> returned an error that matches <code>fs.ErrNotExist<\/code>, so you can test file errors without reading text. The last line shows the danger of <code>%v<\/code>, since the chain is lost. This output sums up Go error wrapping in one screen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Error Wrapping<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Using %v instead of %w<\/strong>: the text looks fine, but the chain is gone. So use <code>%w<\/code> whenever callers may need the cause.<\/li>\n\n\n\n<li><strong>Comparing with ==<\/strong>: the check fails after wrapping. Therefore, use <code>errors.Is<\/code>.<\/li>\n\n\n\n<li><strong>Matching on message text<\/strong>: a small edit breaks the check. Instead, test by value or type.<\/li>\n\n\n\n<li><strong>Wrapping at every layer with the same note<\/strong>: logs become long and repeat themselves. So add new facts only.<\/li>\n\n\n\n<li><strong>Passing a nil error to errors.As without a pointer<\/strong>: this causes a panic. For that reason, pass a pointer to a variable of the target type.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Error Wrapping<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Add context where you know it<\/strong>, such as the function name or the ID.<\/li>\n\n\n\n<li><strong>Keep messages short and lower case<\/strong>, because they join into one long line.<\/li>\n\n\n\n<li><strong>Export sentinel errors<\/strong> that callers need to check, since they become part of your API.<\/li>\n\n\n\n<li><strong>Use custom types for rich data<\/strong>, such as field names or status codes.<\/li>\n\n\n\n<li><strong>Wrap once per layer<\/strong>, and log once at the top.<\/li>\n\n\n\n<li><strong>Do not wrap if the cause should stay private<\/strong>, because wrapping exposes it to callers.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To practise Go error wrapping, add a third function called <code>loadDashboard<\/code> that calls <code>loadProfile<\/code> and wraps the result. Then print the final message for user 7.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hint: the message should read <code>loadDashboard: loadProfile(7): user not found<\/code>. After that, confirm that <code>errors.Is<\/code> still finds <code>ErrNotFound<\/code> from the top.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages describe the packages and ideas used in this lesson.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/errors\">errors package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/blog\/go1.13-errors\">Go blog: Working with Errors in Go 1.13<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/fmt\">fmt package documentation<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go error wrapping adds context and keeps the original cause.<\/li>\n\n\n\n<li>Wrap with <code>fmt.Errorf<\/code> and the <code>%w<\/code> verb.<\/li>\n\n\n\n<li>Use <code>errors.Is<\/code> for values and <code>errors.As<\/code> for types.<\/li>\n\n\n\n<li>Plain <code>==<\/code> fails on wrapped errors.<\/li>\n\n\n\n<li><code>errors.Join<\/code> merges several errors into one.<\/li>\n\n\n\n<li>Using <code>%v<\/code> hides the cause, so use it only when you want that.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By now, you can pass errors up the call stack without losing the cause. However, creating complex objects with many settings is another common task. So next, we will build a clean API with the functional options pattern.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next up: <a href=\"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/\">Go functional options pattern explained<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Go error wrapping lets you add context to an error without losing the original cause. In this post, you will learn how %w, errors.Is,&hellip;<\/p>\n","protected":false},"author":1,"featured_media":441,"comment_status":"","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[91,11,77],"swapz_series":[],"class_list":["post-472","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-error-wrapping","tag-go-lang","tag-intermediate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Error Wrapping with errors.Is and errors.As<\/title>\n<meta name=\"description\" content=\"Learn Go error wrapping with the percent w verb. Use errors.Is, errors.As and errors.Join to keep the cause and add clear context.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Error Wrapping with errors.Is and errors.As\" \/>\n<meta property=\"og:description\" content=\"Learn Go error wrapping with the percent w verb. Use errors.Is, errors.As and errors.Join to keep the cause and add clear context.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-04T03:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-error-wrapping-guide\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-error-wrapping-guide\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Error Wrapping with errors.Is and errors.As\",\"datePublished\":\"2026-06-04T03:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-error-wrapping-guide\\\/\"},\"wordCount\":1473,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-error-wrapping-guide\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-error-wrapping-guide-featured.png\",\"keywords\":[\"Go Error Wrapping\",\"Go Lang\",\"Intermediate\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-error-wrapping-guide\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-error-wrapping-guide\\\/\",\"name\":\"Go Error Wrapping with errors.Is and errors.As\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-error-wrapping-guide\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-error-wrapping-guide\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-error-wrapping-guide-featured.png\",\"datePublished\":\"2026-06-04T03:30:00+00:00\",\"description\":\"Learn Go error wrapping with the percent w verb. Use errors.Is, errors.As and errors.Join to keep the cause and add clear context.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-error-wrapping-guide\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-error-wrapping-guide\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-error-wrapping-guide\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-error-wrapping-guide-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-error-wrapping-guide-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Error Wrapping featured image: wrap, errors.Is and errors.As cards\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-error-wrapping-guide\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Error Wrapping with errors.Is and errors.As\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Error Wrapping with errors.Is and errors.As","description":"Learn Go error wrapping with the percent w verb. Use errors.Is, errors.As and errors.Join to keep the cause and add clear context.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/","og_locale":"en_US","og_type":"article","og_title":"Go Error Wrapping with errors.Is and errors.As","og_description":"Learn Go error wrapping with the percent w verb. Use errors.Is, errors.As and errors.Join to keep the cause and add clear context.","og_url":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-06-04T03:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Error Wrapping with errors.Is and errors.As","datePublished":"2026-06-04T03:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/"},"wordCount":1473,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-featured.png","keywords":["Go Error Wrapping","Go Lang","Intermediate"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/","url":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/","name":"Go Error Wrapping with errors.Is and errors.As","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-featured.png","datePublished":"2026-06-04T03:30:00+00:00","description":"Learn Go error wrapping with the percent w verb. Use errors.Is, errors.As and errors.Join to keep the cause and add clear context.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-error-wrapping-guide-featured.png","width":2400,"height":1260,"caption":"Go Error Wrapping featured image: wrap, errors.Is and errors.As cards"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Error Wrapping with errors.Is and errors.As"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=472"}],"version-history":[{"count":0,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/472\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/441"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=472"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}