Skip to content

Commit

Permalink
fix: allow bare errors from golang.org/x/sys/unix
Browse files Browse the repository at this point in the history
This is my naive (and incomplete) approach to fix GH issue #10.

The problems with this implementation are:
- no test cases (it seems those would need the whole golang.org/x/sys/unix
  to be available under testdata/src);
- a check is too relaxed (ignoring all errors that start from "E" from
  any package named "unix").

Alas, I have no idea how to fix those.

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Jul 28, 2023
1 parent ae40071 commit 06b2464
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions errorlint/allowed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package errorlint
import (
"fmt"
"go/ast"
"strings"
)

var allowedErrors = []struct {
Expand Down Expand Up @@ -101,11 +102,19 @@ func isAllowedErrorComparison(info *TypesInfoExt, binExpr *ast.BinaryExpr) bool
}
}

fmt.Printf("errName: %s\n", errName)
// Unimplemented or not sure, disallow the expression.
if errName == "" || len(callExprs) == 0 {
return false
}

// As an exception, allow all errors from golang.org/x/sys/unix as they are bare.
// Note this check is too relaxed because the package name is not complete.
// See https://github.com/polyfloyd/go-errorlint/issues/10.
if strings.HasPrefix(errName, "unix.E") {
return true
}

// Map call expressions to the function name format of the allow list.
functionNames := make([]string, len(callExprs))
for i, callExpr := range callExprs {
Expand Down

0 comments on commit 06b2464

Please sign in to comment.