ProCoreInterview prep

Go Errors & Edge Cases

The error convention taken seriously: wrapping with %w, errors.Is against errors.As, sentinel values and custom types. Ends with the traps - a nil pointer that is not a nil error, a recover that only works one frame up, and the Close whose error everyone drops.

Questions90
Topics10
Answering time68 minutes
At five a day18 days
LevelCore

Who it is for

Writes the happy path well.

The behaviour people get wrong after they are already productive in the language.

You will get the most out of it if you have written Go recently enough to read it without effort, and have been surprised by it at least once. If you are picking the language up for the first time, start with Go Essentials and come back to this one.

It is also built for interview preparation: the questions are the ones that get asked because they separate people who have read the documentation from people who have hit the behaviour in production.

How long it takes

90 graded questions at roughly 45 seconds each is about 68 minutes of answering in total.

At the default five questions a day, and because the session mixes in your other courses, expect around 18 days — call it 3 weeks — to see everything once, plus a few weeks of thinning reviews after that before it is all mastered.

A question is mastered on the third correct answer, once the gap between reviews has grown past a week — so a course cannot be finished in a weekend however long you sit with it.

Question mix

  • 60 multiple choice
  • 10 concept cards
  • 10 predict the output
  • 10 put it in order
  • 10 matching questions

Syllabus

What you will be asked about

  1. 01

    Errors Are Values

    Explain what the error interface is and how a failure travels back to the caller.

  2. 02

    errors.New vs fmt.Errorf

    Choose between errors.New and fmt.Errorf, and say what %w adds over %v.

  3. 03

    Wrapping and the Error Chain

    Follow an error chain by hand and make a custom type join it.

  4. 04

    Sentinels and errors.Is

    Use errors.Is instead of == so a sentinel check survives being wrapped.

  5. 05

    errors.As and Typed Errors

    Pull a typed error out of a chain with errors.As and read the data it carries.

  6. 06

    Custom Error Types

    Write an error type and decide whether its Error method takes a value or a pointer receiver.

  7. 07

    The Typed-nil Trap

    Explain why a nil *MyErr returned as an error makes err != nil true.

  8. 08

    panic, recover and What recover Returns

    Say where recover works, what it returns, and when it returns nil.

  9. 09

    Deferred Cleanup and the Errors It Drops

    Report an error from a deferred Close without losing the one you already had.

  10. 10

    Why Go Has No Exceptions

    Describe what returning errors costs and buys compared with throwing them.

8 more topics, and all 90 questions

Go Errors & Edge Cases is a Pro course. One subscription opens it and every other course in the catalogue, including the ones still being written.

See pricing Find a free course

A question from this course

Errors Are Values

What does this print?

package main

import "fmt"

func main() {
	var err error
	fmt.Println(err == nil, err)
}
  • Atrue, then a blank
  • BIt does not run: err has no value
  • Ctrue <nil>
  • Dfalse <nil>
Show the answer

C true <nil>

The zero value of any interface is nil, so a declared-but-unassigned error is the absence of an error. fmt prints a nil interface as <nil> rather than an empty string, which is worth knowing when a log line reads failed: <nil>.

The rest of the track

Go at every depth

FreeFoundation

Go Essentials

The behaviour underneath Go's small syntax. Every variable starts at a usable zero value, a string is a sequence of bytes until you range over it, and an unused import stops the build.

90 questions · 68 minutes

ProCore

Go Core

The places Go still surprises people who write it every day. append sometimes mutates the caller's array and sometimes does not, an interface holding a nil pointer is not nil, and a deferred call can rewrite a named return value.

90 questions · 68 minutes

ProCore

Go Data & Collections

Slices, maps and the places they surprise people. Backing arrays shared by accident, append that sometimes writes into the caller's memory, nil maps that read fine and panic on write, and the randomised iteration order that makes a passing test lie.

90 questions · 68 minutes

ProCore

Go Standard Library

The parts of the standard library people reimplement by hand: strings.Builder, the Split and Trim families, strconv against fmt.Sprintf, the fmt verbs, sort.Slice, encoding/json tags, bytes against strings, and io.Reader and io.Writer. Ten packages where a built-in already does the job, and one behaviour in each that is not what you assumed.

90 questions · 68 minutes

ProAdvanced

Go Idioms & Pitfalls

The Go people write out of habit that another language taught them: naked returns, GetX accessors, interfaces declared by the producer, else after a return, errors dropped into the blank identifier, panic as control flow, pointers for small structs, any where a type parameter belongs, a channel where a mutex was simpler, and embedding mistaken for inheritance. Ten habits, each with a snippet that shows what the compiler actually does.

90 questions · 68 minutes

ProAdvancedInterview prep

Go Advanced

The runtime and type-system behaviour that catches confident Go programmers: typed nils, method sets, closed and nil channels, and a defer that rewrites a named return. Every snippet is one you could be handed in a code review.

90 questions · 68 minutes

ProAdvancedInterview prep

Go Performance

What allocation actually costs in Go, and how to see it: escape analysis, slice and map preallocation, strings.Builder, interface boxing, sync.Pool, and a garbage collector described as it is rather than as folklore. Every claim is one you can check with a benchmark or an escape report.

90 questions · 68 minutes

ProCore

Go Testing

What a Go test actually asserts, and where that claim is weaker than it looks. Table-driven cases and subtest names, t.Error against t.Fatal, reflect.DeepEqual and nil against empty, comparing floats, matching errors with errors.Is, seams instead of mocks, golden files, b.N and t.Cleanup.

90 questions · 68 minutes

ProAdvancedInterview prep

Go Interview Questions

The questions Go interviewers actually ask, and the answer under the answer. Slice aliasing, the nil map, the typed-nil interface, WaitGroups and select, defer against named returns, wrapped errors, embedding, receivers, and a closing round of what does this print.

90 questions · 68 minutes

Start Go Errors & Edge Cases
in tomorrow’s session.

Enrol and this course joins your daily five, mixed in with everything else you are studying — 90 questions spread over about 18 days rather than dropped on you at once.

Browse the catalogue