From bb3cd83484bd546e89898117d7dd223c3b28992c Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Mon, 16 Sep 2024 14:55:09 +0200 Subject: [PATCH] Browser: Skip recipe if we encounter an error during a recipe browser run --- cmd/sync.go | 8 ++++---- lib/browser/browser.go | 15 ++++++++------- lib/browser/oauth2.go | 15 ++++++++------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/cmd/sync.go b/cmd/sync.go index d6ccb35..1624742 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -366,7 +366,8 @@ func runSyncCommandLogic(p *tea.Program, logger *slog.Logger, config *syncComman Err: fmt.Errorf("error running browser recipe for supplier `%s`: %w", recipesToExecute[i].recipe.Supplier, err), Completed: true, }) - // We fall through, because recipeResult might be set and contains additional information + // We skip this supplier and continue with the next one + continue } chromeVersion = browserDriver.ChromeVersion @@ -398,7 +399,8 @@ func runSyncCommandLogic(p *tea.Program, logger *slog.Logger, config *syncComman Err: fmt.Errorf("error running browser recipe for supplier `%s`: %w", recipesToExecute[i].recipe.Supplier, err), Completed: true, }) - // We fall through, because recipeResult might be set and contains additional information + // We skip this supplier and continue with the next one + continue } chromeVersion = clientDriver.ChromeVersion @@ -412,8 +414,6 @@ func runSyncCommandLogic(p *tea.Program, logger *slog.Logger, config *syncComman p.Send(buchhalterMetricsRecord{ChromeVersion: chromeVersion}) } - // TODO recipeResult can be empty! (not nil, but without values) - runDataSupplierRecord := repository.RunDataSupplier{ // Recipe Supplier: recipesToExecute[i].recipe.Supplier, diff --git a/lib/browser/browser.go b/lib/browser/browser.go index db45aa7..84c2384 100644 --- a/lib/browser/browser.go +++ b/lib/browser/browser.go @@ -219,8 +219,8 @@ func (b *BrowserDriver) RunRecipe(p *tea.Program, totalStepCount int, stepCountI if lastStepResult.Status == "success" { result = utils.RecipeResult{ Status: "success", - StatusText: recipe.Supplier + ": " + newDocumentsText, - StatusTextFormatted: "- " + textStyleBold(recipe.Supplier) + ": " + newDocumentsText, + StatusText: fmt.Sprintf("%s: %s", recipe.Supplier, newDocumentsText), + StatusTextFormatted: fmt.Sprintf("- %s: %s", textStyleBold(recipe.Supplier), newDocumentsText), LastStepId: fmt.Sprintf("%s-%s-%d-%s", recipe.Supplier, recipe.Version, n, step.Action), LastStepDescription: step.Description, NewFilesCount: b.newFilesCount, @@ -228,8 +228,8 @@ func (b *BrowserDriver) RunRecipe(p *tea.Program, totalStepCount int, stepCountI } else { result = utils.RecipeResult{ Status: "error", - StatusText: recipe.Supplier + "aborted with error.", - StatusTextFormatted: "x " + textStyleBold(recipe.Supplier) + " aborted with error.", + StatusText: fmt.Sprintf("%s aborted with error.", recipe.Supplier), + StatusTextFormatted: fmt.Sprintf("x %s aborted with error.", textStyleBold(recipe.Supplier)), LastStepId: fmt.Sprintf("%s-%s-%d-%s", recipe.Supplier, recipe.Version, n, step.Action), LastStepDescription: step.Description, LastErrorMessage: lastStepResult.Message, @@ -246,11 +246,12 @@ func (b *BrowserDriver) RunRecipe(p *tea.Program, totalStepCount int, stepCountI case <-time.After(b.recipeTimeout): result = utils.RecipeResult{ Status: "error", - StatusText: recipe.Supplier + " aborted with timeout.", - StatusTextFormatted: "x " + textStyleBold(recipe.Supplier) + " aborted with timeout.", + StatusText: fmt.Sprintf("%s aborted with timeout.", recipe.Supplier), + StatusTextFormatted: fmt.Sprintf("x %s aborted with timeout.", textStyleBold(recipe.Supplier)), LastStepId: fmt.Sprintf("%s-%s-%d-%s", recipe.Supplier, recipe.Version, n, step.Action), LastStepDescription: step.Description, - NewFilesCount: b.newFilesCount, + // LastErrorMessage is not set here, because we don't have an error message + NewFilesCount: b.newFilesCount, } err = utils.TruncateDirectory(b.downloadsDirectory) if err != nil { diff --git a/lib/browser/oauth2.go b/lib/browser/oauth2.go index 77204e2..ee834bd 100644 --- a/lib/browser/oauth2.go +++ b/lib/browser/oauth2.go @@ -174,8 +174,8 @@ func (b *ClientAuthBrowserDriver) RunRecipe(p *tea.Program, totalStepCount int, if lastStepResult.Status == "success" { result = utils.RecipeResult{ Status: "success", - StatusText: recipe.Supplier + ": " + newDocumentsText, - StatusTextFormatted: "- " + textStyleBold(recipe.Supplier) + ": " + newDocumentsText, + StatusText: fmt.Sprintf("%s: %s", recipe.Supplier, newDocumentsText), + StatusTextFormatted: fmt.Sprintf("- %s: %s", textStyleBold(recipe.Supplier), newDocumentsText), LastStepId: fmt.Sprintf("%s-%s-%d-%s", recipe.Supplier, recipe.Version, n, step.Action), LastStepDescription: step.Description, NewFilesCount: b.newFilesCount, @@ -183,8 +183,8 @@ func (b *ClientAuthBrowserDriver) RunRecipe(p *tea.Program, totalStepCount int, } else { result = utils.RecipeResult{ Status: "error", - StatusText: recipe.Supplier + " aborted with error.", - StatusTextFormatted: "x " + textStyleBold(recipe.Supplier) + " aborted with error.", + StatusText: fmt.Sprintf("%s aborted with error.", recipe.Supplier), + StatusTextFormatted: fmt.Sprintf("x %s aborted with error.", textStyleBold(recipe.Supplier)), LastStepId: fmt.Sprintf("%s-%s-%d-%s", recipe.Supplier, recipe.Version, n, step.Action), LastStepDescription: step.Description, LastErrorMessage: lastStepResult.Message, @@ -198,11 +198,12 @@ func (b *ClientAuthBrowserDriver) RunRecipe(p *tea.Program, totalStepCount int, case <-time.After(b.recipeTimeout): result = utils.RecipeResult{ Status: "error", - StatusText: recipe.Supplier + " aborted with timeout.", - StatusTextFormatted: "x " + textStyleBold(recipe.Supplier) + " aborted with timeout.", + StatusText: fmt.Sprintf("%s aborted with timeout.", recipe.Supplier), + StatusTextFormatted: fmt.Sprintf("x %s aborted with timeout.", textStyleBold(recipe.Supplier)), LastStepId: fmt.Sprintf("%s-%s-%d-%s", recipe.Supplier, recipe.Version, n, step.Action), LastStepDescription: step.Description, - NewFilesCount: b.newFilesCount, + // LastErrorMessage is not set here, because we don't have an error message + NewFilesCount: b.newFilesCount, } return result, nil }