I create cancellable Go context and I need to cancel it from time to time. Yet, the standard "context cancelled" error message does not seem quite informative to me. I would like to make custom one. But there is no clear way to do that! When you open context
package sources, particularly WithCancel
function, you see that the error Cancelled
is used but actually there's no reason why custom error object is not an argument of CancelFunc
.
The question is, is there a concise way to create cancellable context with custom cancel error message in Go, without copy-pasting WithCancel
source code?