Life of an HTTP request in a Go server (2017)
I am not a Go expert so please correct me if I&#x27;m wrong, but... The fact that the stdlib HTTP utils in Go recover from panics in handlers and provide no way of changing this via easy setting is one of the things that really annoy me. Seemingly, they consider it a backwards compatibility break since it&#x27;s a behavior change that would affect all existing middleware you try to use (see e.g. <a href="https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;go&#x2F;issues&#x2F;16542" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;go&#x2F;issues&#x2F;16542</a>). You need to provide your own error handling middleware (of which several exist).<p>A beginner needs to be very careful and read the docs to catch e.g. this line:<p>&quot;If ServeHTTP panics, the server (the caller of ServeHTTP) assumes that the effect of the panic was isolated to the active request. It recovers the panic, logs a stack trace to the server error log, and either closes the network connection or sends an HTTP&#x2F;2 RST_STREAM, depending on the HTTP protocol. To abort a handler so the client sees an interrupted response but the server doesn&#x27;t log an error, panic with the value ErrAbortHandler. &quot;<p>I think that is an unintuitive assumption that makes for brittle software. Also, the fact that Go kind of blesses the use of panics internally in a library (e.g. &quot;The convention in the Go libraries is that even when a package uses panic internally, its external API still presents explicit error return values.&quot;, <a href="https:&#x2F;&#x2F;blog.golang.org&#x2F;defer-panic-and-recover" rel="nofollow">https:&#x2F;&#x2F;blog.golang.org&#x2F;defer-panic-and-recover</a>) makes for even more brittle software, as predicting what state a control flow interruption like panic through a call stack leaves your data in can be challenging and require great care to avoid invariants being violated. Last I checked, e.g. Rust did not allow the reuse of data owned by a panicking call stack without explicitly asserting that it is still considered valid.<p>I guess I&#x27;m showing my bias for languages that make it harder to make mistakes, but I don&#x27;t like brittle stuff like encouraging panic-like control flow for non-exceptional situations, implicit reuse of &quot;panicked data&quot;, missing non-exhaustive match on enums, missing enums altogether, missing sum types and pattern matching making everything from detailed error management to proper state representation more brittle, etc etc. I&#x27;ll stop there and not get into the rest of the stuff.<p>Go is one of the languages my employer pays me to write and I will say that I have a significantly higher appreciation for it now than when I started (it IS very beginner friendly and very ergonomic in general), but I wish it would help me more to write really robust and correct software.