44package errors
55
66import (
7+ "errors"
78 stderror "errors"
89 "fmt"
910 "strings"
@@ -56,15 +57,6 @@ const (
5657 NotYetAvailable = ConstError ("not yet available" )
5758)
5859
59- // constSuppressor is a small type wrapper for ConstError to surpress the error
60- // value from returning an error value. This allows us to maintain backwards
61- // compatibility.
62- type constSuppressor ConstError
63-
64- func (c constSuppressor ) Error () string { return "" }
65-
66- func (c constSuppressor ) Unwrap () error { return ConstError (c ) }
67-
6860// errWithType is an Err bundled with its error type (a ConstError)
6961type errWithType struct {
7062 error
@@ -96,7 +88,7 @@ func wrapErrorWithMsg(err error, msg string) error {
9688
9789func makeWrappedConstError (err error , format string , args ... interface {}) error {
9890 separator := " "
99- if err .Error () == "" {
91+ if err .Error () == "" || errors . Is ( err , & fmtNoop {}) {
10092 separator = ""
10193 }
10294 return fmt .Errorf (strings .Join ([]string {format , "%w" }, separator ), append (args , err )... )
@@ -196,7 +188,7 @@ func IsUserNotFound(err error) bool {
196188// the Locationer interface.
197189func Unauthorizedf (format string , args ... interface {}) error {
198190 return newLocationError (
199- makeWrappedConstError (constSuppressor (Unauthorized ), format , args ... ),
191+ makeWrappedConstError (Hide (Unauthorized ), format , args ... ),
200192 1 ,
201193 )
202194}
@@ -364,7 +356,7 @@ func IsNotAssigned(err error) bool {
364356// Locationer interface.
365357func BadRequestf (format string , args ... interface {}) error {
366358 return newLocationError (
367- makeWrappedConstError (constSuppressor (BadRequest ), format , args ... ),
359+ makeWrappedConstError (Hide (BadRequest ), format , args ... ),
368360 1 ,
369361 )
370362}
@@ -388,7 +380,7 @@ func IsBadRequest(err error) bool {
388380// and the Locationer interface.
389381func MethodNotAllowedf (format string , args ... interface {}) error {
390382 return newLocationError (
391- makeWrappedConstError (constSuppressor (MethodNotAllowed ), format , args ... ),
383+ makeWrappedConstError (Hide (MethodNotAllowed ), format , args ... ),
392384 1 ,
393385 )
394386}
@@ -412,7 +404,7 @@ func IsMethodNotAllowed(err error) bool {
412404// Locationer interface.
413405func Forbiddenf (format string , args ... interface {}) error {
414406 return newLocationError (
415- makeWrappedConstError (constSuppressor (Forbidden ), format , args ... ),
407+ makeWrappedConstError (Hide (Forbidden ), format , args ... ),
416408 1 ,
417409 )
418410}
@@ -436,7 +428,7 @@ func IsForbidden(err error) bool {
436428// Is(err, QuotaLimitExceeded) and the Locationer interface.
437429func QuotaLimitExceededf (format string , args ... interface {}) error {
438430 return newLocationError (
439- makeWrappedConstError (constSuppressor (QuotaLimitExceeded ), format , args ... ),
431+ makeWrappedConstError (Hide (QuotaLimitExceeded ), format , args ... ),
440432 1 ,
441433 )
442434}
@@ -460,7 +452,7 @@ func IsQuotaLimitExceeded(err error) bool {
460452// and the Locationer interface.
461453func NotYetAvailablef (format string , args ... interface {}) error {
462454 return newLocationError (
463- makeWrappedConstError (constSuppressor (NotYetAvailable ), format , args ... ),
455+ makeWrappedConstError (Hide (NotYetAvailable ), format , args ... ),
464456 1 ,
465457 )
466458}
0 commit comments