style: unify error msg
This commit is contained in:
parent
7ad3a3ab1f
commit
6c8332af29
|
@ -1,12 +1,16 @@
|
|||
package stage
|
||||
|
||||
import "github.com/mitchellh/mapstructure"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
func DecodeConf[T any](confAny any) (*T, error) {
|
||||
var conf T
|
||||
err := mapstructure.Decode(confAny, &conf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("failed to decode conf: %w", err)
|
||||
}
|
||||
return &conf, nil
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ func NonAsciiMsg(root string) error {
|
|||
}
|
||||
|
||||
if !isCommitLegal {
|
||||
return fmt.Errorf("Non-ASCII characters in commit messages:\n%s", msg)
|
||||
return fmt.Errorf("non-ASCII characters in commit messages:\n%s", msg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func getForbiddens(root string, fileList []string, localList string) ([]string,
|
|||
if localList != "" {
|
||||
file, err := os.Open(localList)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to open file %s: %v\n", localList, err)
|
||||
return nil, fmt.Errorf("failed to open file %s: %v\n", localList, err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
|
@ -35,7 +35,7 @@ func getForbiddens(root string, fileList []string, localList string) ([]string,
|
|||
dirs = append(dirs, scanner.Text())
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, fmt.Errorf("Error reading file %s: %v\n", localList, err)
|
||||
return nil, fmt.Errorf("error reading file %s: %v\n", localList, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ func ForbiddenCheck(rootDir string, regexList []string, localList string, repo s
|
|||
}
|
||||
|
||||
if len(forbids) > 0 {
|
||||
return fmt.Errorf("The following forbidden files were found: %s\n\nTo fix it, first make a backup of your repository and then run the following commands:\nfor i in %s%s",
|
||||
return fmt.Errorf("the following forbidden files were found: %s\n\nTo fix it, first make a backup of your repository and then run the following commands:\nfor i in %s%s",
|
||||
strings.Join(forbids, ", "),
|
||||
strings.Join(forbids, " "),
|
||||
fmt.Sprint(
|
||||
|
|
|
@ -20,7 +20,7 @@ func getNonAscii(root string, localList string) ([]string, error) {
|
|||
if localList != "" {
|
||||
file, err := os.Open(localList)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to open file %s: %v\n", localList, err)
|
||||
return nil, fmt.Errorf("failed to open file %s: %v\n", localList, err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
|
@ -29,7 +29,7 @@ func getNonAscii(root string, localList string) ([]string, error) {
|
|||
dirs = append(dirs, scanner.Text())
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, fmt.Errorf("Error reading file %s: %v\n", localList, err)
|
||||
return nil, fmt.Errorf("error reading file %s: %v\n", localList, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ func NonAsciiFiles(root string, localList string) error {
|
|||
return fmt.Errorf("error getting non-ascii: %w", err)
|
||||
}
|
||||
if len(nonAscii) > 0 {
|
||||
return fmt.Errorf("Non-ASCII characters found in the following files:\n%s",
|
||||
return fmt.Errorf("non-ASCII characters found in the following files:\n%s",
|
||||
strings.Join(nonAscii, "\n"))
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -34,7 +34,7 @@ func RepoSize() error {
|
|||
}
|
||||
}
|
||||
if sum > 2048 {
|
||||
return fmt.Errorf("Repository larger than 2MB. Please clean up or contact the teaching team.")
|
||||
return fmt.Errorf("repository larger than 2MB. Please clean up or contact the teaching team.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ func CheckTags(repoPath string, category string, n int) error {
|
|||
}
|
||||
}
|
||||
if !found {
|
||||
return fmt.Errorf("Wrong release tag '%s' or missing release tags. Please use one of '%s'.", target, strings.Join(tags, "', '"))
|
||||
return fmt.Errorf("wrong release tag '%s' or missing release tags. Please use one of '%s'.", target, strings.Join(tags, "', '"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ func getRegex(fileList []string) ([]*regexp.Regexp, error) {
|
|||
for _, pattern := range fileList {
|
||||
regex, err := regexp.Compile("(?i)" + pattern)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error compiling regex:%w", err)
|
||||
return nil, fmt.Errorf("error compiling regex: %w", err)
|
||||
}
|
||||
regexList = append(regexList, regex)
|
||||
}
|
||||
|
|
|
@ -33,10 +33,10 @@ func checkFileChecksum(rootDir, fileName, expectedChecksum string) error {
|
|||
filePath := filepath.Join(rootDir, strings.TrimSpace(fileName))
|
||||
actualChecksum, err := getChecksum(filePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reading file %s: %v", filePath, err)
|
||||
return fmt.Errorf("error reading file %s: %v", filePath, err)
|
||||
}
|
||||
if actualChecksum != expectedChecksum {
|
||||
return fmt.Errorf("Checksum for %s failed. Expected %s, but got %s. Please revert your changes or contact the teaching team if you have a valid reason for adjusting them.", filePath, expectedChecksum, actualChecksum)
|
||||
return fmt.Errorf("checksum for %s failed. Expected %s, but got %s. Please revert your changes or contact the teaching team if you have a valid reason for adjusting them.", filePath, expectedChecksum, actualChecksum)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func VerifyFiles(rootDir string, checkFileNameList string, checkFileSumList stri
|
|||
checkSums := strings.Split(checkFileSumList, ",")
|
||||
// Check if the number of files matches the number of checksums
|
||||
if len(fileNames) != len(checkSums) {
|
||||
return fmt.Errorf("Error: The number of files and checksums do not match.")
|
||||
return fmt.Errorf("the number of files and checksums do not match")
|
||||
}
|
||||
// Check each file's checksum
|
||||
for i, fileName := range fileNames {
|
||||
|
|
Loading…
Reference in New Issue
Block a user