0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-24 21:20:40 +00:00

fix: add better logs on fatal errors

This commit is contained in:
Beatriz Vieira 2021-07-31 18:20:56 -03:00
parent 10ec6f18c4
commit 721e39feb1
2 changed files with 11 additions and 7 deletions

View File

@ -1,7 +1,6 @@
package main
import (
"errors"
"fmt"
"io/ioutil"
"log"
@ -24,7 +23,7 @@ func loadEnvConfig() EnvConfig {
var c EnvConfig
err := envconfig.Process("", &c)
if err != nil {
log.Fatal(err.Error())
log.Fatal("failed to load env config, error: ", err.Error())
}
return c
}
@ -43,11 +42,16 @@ func getRepoPath() (string, error) {
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
out, err := cmd.CombinedOutput()
if err != nil {
return "", errors.New(string(out))
return "", combinedOutputErr(err, out)
}
return strings.TrimSpace(string(out)), nil
}
func combinedOutputErr(err error, out []byte) error {
msg := strings.Split(string(out), "\n")
return fmt.Errorf("%v - %s", err, msg[0])
}
func loadConfig(filepath string) (Config, error) {
content, rerr := ioutil.ReadFile(filepath)
if rerr != nil {

View File

@ -27,19 +27,19 @@ func main() {
if envCfg.Home != "" {
if homeCfg, err := loadConfig(filepath.Join(envCfg.Home, configFilename)); err == nil {
if merr := merge(&cfg, homeCfg); merr != nil {
log.Fatal(merr)
log.Fatal("failed to merge user config, error: ", merr)
}
}
}
repoPath, rerr := getRepoPath()
if rerr != nil {
log.Fatal(rerr)
log.Fatal("failed to get repository path, error: ", rerr)
}
if repoCfg, err := loadConfig(filepath.Join(repoPath, repoConfigFilename)); err == nil {
if merr := merge(&cfg, repoCfg); merr != nil {
log.Fatal(merr)
log.Fatal("failed to merge repo config, error: ", merr)
}
if len(repoCfg.ReleaseNotes.Headers) > 0 { // mergo is merging maps, headers will be overwritten
cfg.ReleaseNotes.Headers = repoCfg.ReleaseNotes.Headers
@ -165,6 +165,6 @@ func main() {
}
if apperr := app.Run(os.Args); apperr != nil {
log.Fatal(apperr)
log.Fatal("failed to run cli, error: ", apperr)
}
}