-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Closed as not planned
Labels
FrozenDueToAgeProposalerror-handlingLanguage & library change proposals that are about error handling.Language & library change proposals that are about error handling.v2An incompatible library changeAn incompatible library change
Milestone
Description
Problem
Most of the time in Go if an error occurs it can be returned. There are certain cases when this is not possible, usually go functions.
go func(){
if err := foo(); err != nil {
// cannot 'return err' because the function has already returned
}
}
Packages shouldn't choose how to handle errors so they end up either squashing the error or making configurable error logging like ErrorLog in httputil.ReverseProxy or http.Server.
Proposal
I propose adding a function errors.Handle(error) that can be called in cases where it is impossible to return an error.
There should be a second function errors.SetHandler(func(error)) that can be called, usually in main, that lets an application choose how to handle an error. (i.e. log, increment a metrics, ...)
OneOfOne, tmthrgd, earthboundkid, nange, pgaskin and 3 more
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeProposalerror-handlingLanguage & library change proposals that are about error handling.Language & library change proposals that are about error handling.v2An incompatible library changeAn incompatible library change