Skip to content

Commit

Permalink
Browser: Skip recipe if we encounter an error during a recipe browser…
Browse files Browse the repository at this point in the history
… run
  • Loading branch information
andygrunwald committed Sep 16, 2024
1 parent 26830e6 commit bb3cd83
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
8 changes: 4 additions & 4 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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,
Expand Down
15 changes: 8 additions & 7 deletions lib/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,17 @@ 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,
}
} 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,
Expand All @@ -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 {
Expand Down
15 changes: 8 additions & 7 deletions lib/browser/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,17 @@ 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,
}
} 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,
Expand All @@ -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
}
Expand Down

0 comments on commit bb3cd83

Please sign in to comment.