From 44e0ea254bd9e17d2679ddcba1a1ef64e298c1c9 Mon Sep 17 00:00:00 2001 From: quobix Date: Fri, 1 Dec 2023 14:33:25 -0500 Subject: [PATCH] Fixing git history error handling for commands. Signed-off-by: quobix --- builder/tree.go | 4 ---- cmd/html_report.go | 7 +++++++ cmd/report.go | 13 +++++++++---- cmd/summary.go | 1 + 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/builder/tree.go b/builder/tree.go index ee4e651..61b176d 100644 --- a/builder/tree.go +++ b/builder/tree.go @@ -4,7 +4,6 @@ package builder import ( - "fmt" v3 "github.com/pb33f/libopenapi/datamodel/low/v3" wcModel "github.com/pb33f/libopenapi/what-changed/model" "github.com/pb33f/libopenapi/what-changed/reports" @@ -287,9 +286,6 @@ func extractChangeCount(change reports.HasChanges) (int, int) { func DigIntoTreeNode[T any](parent *model.TreeNode, field reflect.Value, label string, tc, br int) { if !field.IsZero() { - if label == "path" { - fmt.Println("hello") - } e := &model.TreeNode{ TitleString: label, Key: uuid.NewV4().String(), diff --git a/cmd/html_report.go b/cmd/html_report.go index 33486b8..ea18009 100644 --- a/cmd/html_report.go +++ b/cmd/html_report.go @@ -307,18 +307,25 @@ func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool, err := errors.New("please supply a path to a git repo via -r, and a path to a file via -f") model.SendProgressError("reading paths", err.Error(), errorChan) + close(progressChan) return nil, nil, []error{err} } // build commit history. commitHistory, err := git.ExtractHistoryFromFile(gitPath, filePath, progressChan, errorChan) if err != nil { + model.SendFatalError("extraction", + fmt.Sprintf("cannot extract history %s", errors.Join(err...)), errorChan) + close(progressChan) return nil, nil, err } // populate history with changes and data commitHistory, err = git.PopulateHistoryWithChanges(commitHistory, 0, progressChan, errorChan, base, remote) if err != nil { + model.SendFatalError("extraction", + fmt.Sprintf("cannot extract history %s", errors.Join(err...)), errorChan) + close(progressChan) return nil, nil, err } diff --git a/cmd/report.go b/cmd/report.go index d724c09..7f8b117 100644 --- a/cmd/report.go +++ b/cmd/report.go @@ -57,6 +57,7 @@ func GetReportCommand() *cobra.Command { } listenForUpdates := func(updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError) { + for { select { case _, ok := <-updateChan: @@ -65,9 +66,7 @@ func GetReportCommand() *cobra.Command { return } case <-errorChan: - failed = true - doneChan <- true - return + // do nothing. } } } @@ -93,7 +92,7 @@ func GetReportCommand() *cobra.Command { } report, er := runGithubHistoryReport(user, repo, filePath, latestFlag, limitFlag, updateChan, errorChan, baseFlag, remoteFlag) - + // wait for things to be completed. <-doneChan @@ -220,6 +219,7 @@ func runGitHistoryReport(gitPath, filePath string, latest bool, if gitPath == "" || filePath == "" { err := errors.New("please supply a path to a git repo via -r, and a path to a file via -f") model.SendProgressError("git", err.Error(), errorChan) + close(updateChan) return nil, []error{err} } @@ -230,6 +230,8 @@ func runGitHistoryReport(gitPath, filePath string, latest bool, // build commit history. commitHistory, err := git.ExtractHistoryFromFile(gitPath, filePath, updateChan, errorChan) if err != nil { + model.SendProgressError("git", fmt.Sprintf("%d errors found building history", len(err)), errorChan) + close(updateChan) return nil, err } @@ -237,6 +239,7 @@ func runGitHistoryReport(gitPath, filePath string, latest bool, commitHistory, err = git.PopulateHistoryWithChanges(commitHistory, 0, updateChan, errorChan, base, remote) if err != nil { model.SendProgressError("git", fmt.Sprintf("%d errors found extracting history", len(err)), errorChan) + close(updateChan) return nil, err } @@ -271,6 +274,8 @@ func runGithubHistoryReport(username, repo, filePath string, latest bool, limit commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, false, limit, base, remote) if errs != nil { + model.SendProgressError("git", errors.Join(errs...).Error(), errorChan) + close(progressChan) return nil, errs } diff --git a/cmd/summary.go b/cmd/summary.go index 1c2b085..8385c5e 100644 --- a/cmd/summary.go +++ b/cmd/summary.go @@ -369,6 +369,7 @@ func runGitHistorySummary(gitPath, filePath string, latest bool, commitHistory, errs := git.ExtractHistoryFromFile(gitPath, filePath, updateChan, errorChan) if errs != nil { model.SendProgressError("git", fmt.Sprintf("%d errors found extracting history", len(errs)), errorChan) + close(updateChan) return errs[0] }