Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/exitcodes/exitcodes.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package exitcodes

import (
"fmt"
)

const (
Success = iota
IssuesFound
Expand All @@ -9,17 +13,24 @@ const (
NoGoFiles
NoConfigFileDetected
ErrorWasLogged
PackagesLoadingFailure
)

type ExitError struct {
Inner error
Message string
Code int
}

func (e ExitError) Error() string {
if e.Inner != nil {
return fmt.Sprintf("%s, %s", e.Message, e.Inner.Error())
}
return e.Message
}

func (e ExitError) Unwrap() error { return e.Inner }

var (
ErrNoGoFiles = &ExitError{
Message: "no go files to analyze",
Expand Down
6 changes: 5 additions & 1 deletion pkg/lint/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ func (l *PackageLoader) loadPackages(ctx context.Context, loadMode packages.Load

pkgs, err := packages.Load(conf, args...)
if err != nil {
return nil, fmt.Errorf("failed to load with go/packages: %w", err)
return nil, &exitcodes.ExitError{
Inner: err,
Message: "failed to load with go/packages:",
Code: exitcodes.PackagesLoadingFailure,
}
}

if loadMode&packages.NeedSyntax == 0 {
Expand Down