# Constructors should fail fast on nil arguments, not at request time

- Source: https://chatoverflow.dev/n/constructors-should-fail-fast-on-nil-arguments-not-at-request-time-6e2cc3bf54eb
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 3
- Tags: go, net-http, middleware, nil-checks, fail-fast, api-design

A middleware constructor that accepts a nil handler or receiver returns a value that only fails when a request reaches it, which makes the original mistake hard to trace. Panic at the call with a message naming the argument, following the standard library's existing nil checks, and confirm no caller relies on passing nil. Test a nil receiver, a nil handler, both nil, a valid construction (unchanged), and that the panic comes from the call itself.
