feat: improved error messages

This commit is contained in:
Simon Cornet 2025-03-04 14:07:29 +01:00
commit 1c2be88daa
4 changed files with 11 additions and 11 deletions

View file

@ -76,7 +76,7 @@ func pullRepository(repoName string, repoDestination string) {
remoteCmd := exec.Command("git", "-C", repoDestination, "remote", "show") remoteCmd := exec.Command("git", "-C", repoDestination, "remote", "show")
remoteOutput, err := remoteCmd.CombinedOutput() remoteOutput, err := remoteCmd.CombinedOutput()
if err != nil { if err != nil {
return "", fmt.Errorf("finding remote: %v", err) return "", fmt.Errorf("finding remote: %v\n", err)
} }
remote := strings.Split(strings.TrimSpace(string(remoteOutput)), "\n")[0] remote := strings.Split(strings.TrimSpace(string(remoteOutput)), "\n")[0]

View file

@ -29,7 +29,7 @@ func fetchRepositoriesGitlab() ([]Repository, error) {
req, err := http.NewRequest("GET", url, nil) req, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {
return nil, fmt.Errorf("creating request: %v", err) return nil, fmt.Errorf("creating request: %v\n", err)
} }
req.Header.Set("PRIVATE-TOKEN", gitlabToken) req.Header.Set("PRIVATE-TOKEN", gitlabToken)
@ -37,21 +37,21 @@ func fetchRepositoriesGitlab() ([]Repository, error) {
client := &http.Client{} client := &http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
return nil, fmt.Errorf("making request: %v", err) return nil, fmt.Errorf("making request: %v\n", err)
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("API request failed with status: %d", resp.StatusCode) return nil, fmt.Errorf("API request failed with status: %d\n", resp.StatusCode)
} }
var repositories []Repository var repositories []Repository
if err := json.NewDecoder(resp.Body).Decode(&repositories); err != nil { if err := json.NewDecoder(resp.Body).Decode(&repositories); err != nil {
return nil, fmt.Errorf("decoding response: %v", err) return nil, fmt.Errorf("decoding response: %v\n", err)
} }
if len(repositories) < 1 { if len(repositories) < 1 {
return repositories, fmt.Errorf("no repositories found") return repositories, fmt.Errorf("no repositories found\n")
} }
return repositories, nil return repositories, nil

View file

@ -29,7 +29,7 @@ func manageArguments() {
gitlabToken = envToken gitlabToken = envToken
default: default:
flag.Usage() flag.Usage()
log.Printf("fatal: config; gitlab api token not found") log.Printf("fatal: config; gitlab api token not found\n")
} }
// manage gitlab url option // manage gitlab url option
@ -38,7 +38,7 @@ func manageArguments() {
gitlabHost = envHost gitlabHost = envHost
default: default:
flag.Usage() flag.Usage()
log.Fatalf("fatal: config; gitlab host not found") log.Fatalf("fatal: config; gitlab host not found\n")
} }
// manage destination option // manage destination option
@ -47,7 +47,7 @@ func manageArguments() {
repoDestinationPre = envRepoDest repoDestinationPre = envRepoDest
default: default:
flag.Usage() flag.Usage()
log.Fatalf("fatal: config; destination not found") log.Fatalf("fatal: config; destination not found\n")
} }
// add slash 🎩🎸 if not provided // add slash 🎩🎸 if not provided
@ -72,6 +72,6 @@ func manageArguments() {
default: default:
flag.Usage() flag.Usage()
log.Fatalf("fatal: config; no or wrong archive option found") log.Fatalf("fatal: config; no or wrong archive option found\n")
} }
} }

View file

@ -41,7 +41,7 @@ func progressBar(repositories []Repository) {
func progressBarAdd(amount int) { func progressBarAdd(amount int) {
if err := bar.Add(amount); err != nil { if err := bar.Add(amount); err != nil {
log.Printf("Progress bar update error: %v", err) log.Printf("Progress bar update error: %v\n", err)
} }
} }