More linting

This commit is contained in:
Paul Tötterman
2021-02-10 16:34:20 +02:00
parent b562bd2dc5
commit ddec572d5d
29 changed files with 275 additions and 107 deletions

View File

@@ -1,6 +1,7 @@
package utils
import (
"errors"
"fmt"
"regexp"
"strconv"
@@ -30,7 +31,8 @@ func NewBuildError(message string, args ...interface{}) (b *BuildError) {
// Returns a new BuildError if err is not nil.
func NewBuildIfError(err error, message string, args ...interface{}) (b error) {
if err != nil {
if berr, ok := err.(*BuildError); ok {
var berr *BuildError
if errors.As(err, &berr) {
// This is already a build error so just append the args
berr.Args = append(berr.Args, args...)
return berr
@@ -50,16 +52,16 @@ func (b *BuildError) Error() string {
// Parse the output of the "go build" command.
// Return a detailed Error.
func NewCompileError(importPath, errorLink string, error error) *SourceError {
func NewCompileError(importPath, errorLink string, err error) *SourceError {
// Get the stack from the error
errorMatch := regexp.MustCompile(`(?m)^([^:#]+):(\d+):(\d+:)? (.*)$`).
FindSubmatch([]byte(error.Error()))
FindSubmatch([]byte(err.Error()))
if errorMatch == nil {
errorMatch = regexp.MustCompile(`(?m)^(.*?):(\d+):\s(.*?)$`).FindSubmatch([]byte(error.Error()))
errorMatch = regexp.MustCompile(`(?m)^(.*?):(\d+):\s(.*?)$`).FindSubmatch([]byte(err.Error()))
if errorMatch == nil {
Logger.Error("Failed to parse build errors", "error", error)
Logger.Error("Failed to parse build errors", "error", err)
return &SourceError{
SourceType: "Go code",
Title: "Go Compilation Error",
@@ -69,7 +71,7 @@ func NewCompileError(importPath, errorLink string, error error) *SourceError {
errorMatch = append(errorMatch, errorMatch[3])
Logger.Error("Build errors", "errors", error)
Logger.Error("Build errors", "errors", err)
}
// Read the source for the offending file.

View File

@@ -150,8 +150,9 @@ func MustChmod(filename string, mode os.FileMode) {
// Called if panic.
func PanicOnError(err error, msg string) {
if revErr, ok := err.(*SourceError); (ok && revErr != nil) || (!ok && err != nil) {
Logger.Panicf("Abort: %s: %s %s", msg, revErr, err)
var serr *SourceError
if (errors.As(err, &serr) && serr != nil) || err != nil {
Logger.Panicf("Abort: %s: %s %s", msg, serr, err)
}
}
@@ -348,9 +349,17 @@ func FindSrcPaths(appPath string, packageList []string, packageResolver func(pkg
return
}
// Error is used for constant errors.
type Error string
// Error implements the error interface.
func (e Error) Error() string {
return string(e)
}
var (
NO_APP_FOUND = errors.New("no app found")
NO_REVEL_FOUND = errors.New("no revel found")
ErrNoApp Error = "no app found"
ErrNoRevel Error = "no revel found"
)
// Find the full source dir for the import path, uses the build.Default.GOPATH to search for the directory.
@@ -387,9 +396,9 @@ func findSrcPaths(appPath string, packagesList []string) (sourcePathsmap map[str
}
if !found {
if packageName == "github.com/revel/revel" {
err = NO_REVEL_FOUND
err = ErrNoRevel
} else {
err = NO_APP_FOUND
err = ErrNoApp
}
missingList = append(missingList, packageName)
}

View File

@@ -33,7 +33,7 @@ func InitLogger(basePath string, logLevel logger.LogLevel) {
// This function is to throw a panic that may be caught by the packger so it can perform the needed
// imports.
func Retry(format string, args ...interface{}) {
func Retryf(format string, args ...interface{}) {
// Ensure the user's command prompt starts on the next line.
if !strings.HasSuffix(format, "\n") {
format += "\n"