Skip to content

Commit a2a41a4

Browse files
authored
fix(internal/librarian): wrap error to provide more context for commitAndPush (#2767)
Wrap lower level errors and provide more context of the failure. Fixes #2688
1 parent d5ac6c8 commit a2a41a4

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

internal/gitrepo/gitrepo.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,7 @@ func (r *LocalRepository) Commit(msg string) error {
220220
return err
221221
}
222222

223-
// Log commit hash (brief) and subject line (first line of commit)
224-
subject := strings.Split(msg, "\n")[0]
225-
slog.Info(fmt.Sprintf("Committed %s: '%s'", hash.String()[0:7], subject))
223+
slog.Info("committed", "short_hash", hash.String()[0:7], "subject", strings.Split(msg, "\n")[0])
226224
return nil
227225
}
228226

internal/librarian/command.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,11 @@ func commitAndPush(ctx context.Context, info *commitInfo) error {
381381

382382
repo := info.languageRepo
383383
if err := repo.AddAll(); err != nil {
384-
return err
384+
return fmt.Errorf("failed to add all files to git: %w", err)
385385
}
386386
isClean, err := repo.IsClean()
387387
if err != nil {
388-
return err
388+
return fmt.Errorf("failed to check if repo is clean: %w", err)
389389
}
390390

391391
if isClean {
@@ -396,11 +396,11 @@ func commitAndPush(ctx context.Context, info *commitInfo) error {
396396
datetimeNow := formatTimestamp(time.Now())
397397
branch := fmt.Sprintf("librarian-%s", datetimeNow)
398398
if err := repo.CreateBranchAndCheckout(branch); err != nil {
399-
return err
399+
return fmt.Errorf("failed to create branch and checkout: %w", err)
400400
}
401401

402402
if err := repo.Commit(info.commitMessage); err != nil {
403-
return err
403+
return fmt.Errorf("failed to commit: %w", err)
404404
}
405405

406406
if !info.push {
@@ -409,7 +409,7 @@ func commitAndPush(ctx context.Context, info *commitInfo) error {
409409
}
410410

411411
if err := repo.Push(branch); err != nil {
412-
return err
412+
return fmt.Errorf("failed to push: %w", err)
413413
}
414414

415415
gitHubRepo, err := GetGitHubRepositoryFromGitRepo(info.languageRepo)

internal/librarian/generate_command.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ func (r *generateRunner) run(ctx context.Context) error {
198198
prBodyBuilder: prBodyBuilder,
199199
}
200200

201-
return commitAndPush(ctx, commitInfo)
201+
if err := commitAndPush(ctx, commitInfo); err != nil {
202+
return fmt.Errorf("failed to commit and push changes: %w", err)
203+
}
204+
return nil
202205
}
203206

204207
// generateSingleLibrary manages the generation of a single client library.

0 commit comments

Comments
 (0)