Skip to content

Commit

Permalink
feat(vcs): harden codebase against possible panic scenarios
Browse files Browse the repository at this point in the history
Signed-off-by: hainenber <[email protected]>
  • Loading branch information
hainenber committed Jun 3, 2024
1 parent 0b784c8 commit 6d3d408
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
6 changes: 2 additions & 4 deletions internal/runtime/internal/importsource/import_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,10 @@ func (im *ImportGit) Update(args component.Arguments) (err error) {
if im.repo == nil || !reflect.DeepEqual(repoOpts, im.repoOpts) {
r, err := vcs.NewGitRepo(context.Background(), repoPath, repoOpts)
if err != nil {
isUpdateFailedError := errors.As(err, &vcs.UpdateFailedError{})
if isUpdateFailedError {
if errors.As(err, &vcs.UpdateFailedError{}) {
level.Error(im.log).Log("msg", "failed to update repository", "err", err)
im.updateHealth(err)
}
if errors.As(err, &vcs.InvalidRevisionError{}) || !isUpdateFailedError {
} else {
return err
}
}
Expand Down
5 changes: 1 addition & 4 deletions internal/vcs/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ func NewGitRepo(ctx context.Context, storagePath string, opts GitRepoOptions) (*
if errors.Is(checkoutErr, plumbing.ErrReferenceNotFound) {
return nil, InvalidRevisionError{opts.Revision}
}
return nil, UpdateFailedError{
Repository: opts.Repository,
Inner: checkoutErr,
}
return nil, checkoutErr
}

return &GitRepo{
Expand Down

0 comments on commit 6d3d408

Please sign in to comment.