@@ -83,6 +83,10 @@ type WrapcheckConfig struct {
8383 // returned from any function whose call is defined on a interface named 'Transactor'
8484 // or 'Transaction' due to the name matching the regular expression `Transac(tor|tion)`.
8585 IgnoreInterfaceRegexps []string `mapstructure:"ignoreInterfaceRegexps" yaml:"ignoreInterfaceRegexps"`
86+
87+ // ReportInternalErrors determines whether wrapcheck should report errors returned
88+ // from inside the package.
89+ ReportInternalErrors bool `mapstructure:"reportInternalErrors" yaml:"reportInternalErrors"`
8690}
8791
8892func NewDefaultConfig () WrapcheckConfig {
@@ -273,16 +277,31 @@ func reportUnwrapped(
273277 pkgGlobs []glob.Glob ,
274278) {
275279
280+ if cfg .ReportInternalErrors {
281+ // Check if the call is package-internal function
282+ fnIdent , ok := call .Fun .(* ast.Ident )
283+ if ok {
284+ fnSig := pass .TypesInfo .ObjectOf (fnIdent ).String ()
285+
286+ // Check for ignored signatures
287+ if checkSignature (cfg , regexpsSig , fnSig ) {
288+ return
289+ }
290+
291+ pass .Reportf (tokenPos , "package-internal error should be wrapped: sig: %s" , fnSig )
292+ return
293+ }
294+ }
295+
276296 sel , ok := call .Fun .(* ast.SelectorExpr )
277297 if ! ok {
278298 return
279299 }
280300
281- // Check for ignored signatures
282301 fnSig := pass .TypesInfo .ObjectOf (sel .Sel ).String ()
283- if contains ( cfg . IgnoreSigs , fnSig ) || contains ( cfg . ExtraIgnoreSigs , fnSig ) {
284- return
285- } else if containsMatch ( regexpsSig , fnSig ) {
302+
303+ // Check for ignored signatures
304+ if checkSignature ( cfg , regexpsSig , fnSig ) {
286305 return
287306 }
288307
@@ -305,6 +324,17 @@ func reportUnwrapped(
305324 pass .Reportf (tokenPos , "error returned from external package is unwrapped: sig: %s" , fnSig )
306325 return
307326 }
327+
328+ // If `ReportInternalErrors` is true, report package-internal errors
329+ if cfg .ReportInternalErrors {
330+ pass .Reportf (tokenPos , "package-internal error should be wrapped: sig: %s" , fnSig )
331+ return
332+ }
333+ }
334+
335+ // checkSignature returns whether the function should be ignored.
336+ func checkSignature (cfg WrapcheckConfig , regexpsSig []* regexp.Regexp , fnSig string ) bool {
337+ return contains (cfg .IgnoreSigs , fnSig ) || contains (cfg .ExtraIgnoreSigs , fnSig ) || containsMatch (regexpsSig , fnSig )
308338}
309339
310340// isInterface returns whether the function call is one defined on an interface.
0 commit comments