wrap all errors in services/f3/util/path.go

This commit is contained in:
limiting-factor 2026-05-25 10:27:51 +02:00
parent 6697b56029
commit 39cf80ca4b
No known key found for this signature in database
GPG key ID: FBFC3FECD17D904F

View file

@ -20,7 +20,7 @@ import (
func getF3PathOfRepository(ctx context.Context, repository *repo.Repository) (string, error) {
if err := repository.LoadOwner(ctx); err != nil {
return "", fmt.Errorf("LoadOwner: %w", err)
return "", fmt.Errorf("getF3PathOfRepository LoadOwner: %w", err)
}
var ownerPath string
if repository.Owner.Type == user.UserTypeOrganization {
@ -33,18 +33,18 @@ func getF3PathOfRepository(ctx context.Context, repository *repo.Repository) (st
func convertForgejoPullRequestToF3Path(ctx context.Context, pullRequest *issues.PullRequest) (string, error) {
if err := pullRequest.LoadIssue(ctx); err != nil {
return "", fmt.Errorf("LoadIssue: %w", err)
return "", fmt.Errorf("convertForgejoPullRequestToF3Path LoadIssue: %w", err)
}
return convertForgejoIssueToF3Path(ctx, true, pullRequest.Issue)
}
func convertForgejoIssueToF3Path(ctx context.Context, isPull bool, issue *issues.Issue) (string, error) {
if err := issue.LoadRepo(ctx); err != nil {
return "", fmt.Errorf("LoadRepo: %w", err)
return "", fmt.Errorf("convertForgejoIssueToF3Path LoadRepo: %w", err)
}
projectPath, err := getF3PathOfRepository(ctx, issue.Repo)
if err != nil {
return "", err
return "", fmt.Errorf("convertForgejoIssueToF3Path getF3PathOfRepository: %w", err)
}
var issuePath string
if isPull {
@ -57,11 +57,11 @@ func convertForgejoIssueToF3Path(ctx context.Context, isPull bool, issue *issues
func convertForgejoCommentToF3Path(ctx context.Context, comment *issues.Comment) (string, error) {
if err := comment.LoadIssue(ctx); err != nil {
return "", fmt.Errorf("LoadIssue: %w", err)
return "", fmt.Errorf("convertForgejoCommentToF3Path LoadIssue: %w", err)
}
commentablePath, err := convertForgejoIssueToF3Path(ctx, comment.Issue.IsPull, comment.Issue)
if err != nil {
return "", err
return "", fmt.Errorf("convertForgejoCommentToF3Path convertForgejoIssueToF3Path: %w", err)
}
switch comment.Type {
@ -70,7 +70,7 @@ func convertForgejoCommentToF3Path(ctx context.Context, comment *issues.Comment)
case issues.CommentTypeReview, issues.CommentTypeCode:
review, err := issues.GetReviewByID(ctx, comment.ReviewID)
if err != nil {
return "", fmt.Errorf("GetReviewByID: %w", err)
return "", fmt.Errorf("convertForgejoCommentToF3Path GetReviewByID: %w", err)
}
reviewPath, err := convertForgejoReviewToF3Path(ctx, review)
if err != nil {
@ -78,7 +78,7 @@ func convertForgejoCommentToF3Path(ctx context.Context, comment *issues.Comment)
}
return f3_tree.NewReviewCommentPathString(reviewPath, f3_util.ToString(comment.ID)), nil
default:
err := fmt.Errorf("unexpected comment type %v", comment.Type)
err := fmt.Errorf("convertForgejoCommentToF3Path unexpected comment type %v", comment.Type)
log.Error(err.Error())
return "", err
}
@ -86,11 +86,11 @@ func convertForgejoCommentToF3Path(ctx context.Context, comment *issues.Comment)
func convertForgejoReleaseToF3Path(ctx context.Context, release *repo.Release) (string, error) {
if err := release.LoadRepo(ctx); err != nil {
return "", fmt.Errorf("LoadRepo: %w", err)
return "", fmt.Errorf("convertForgejoReleaseToF3Path LoadRepo: %w", err)
}
projectPath, err := getF3PathOfRepository(ctx, release.Repo)
if err != nil {
return "", err
return "", fmt.Errorf("convertForgejoReleaseToF3Path getF3PathOfRepository: %w", err)
}
return f3_tree.NewReleasePathString(projectPath, f3_util.ToString(release.ID)), nil
}
@ -101,33 +101,33 @@ func convertForgejoAttachmentToF3Path(ctx context.Context, attachment *repo.Atta
if attachment.CommentID != 0 {
comment, err := issues.GetCommentByID(ctx, attachment.CommentID)
if err != nil {
return "", fmt.Errorf("GetCommentByID: %w", err)
return "", fmt.Errorf("convertForgejoAttachmentToF3Path GetCommentByID: %w", err)
}
attachablePath, err = convertForgejoCommentToF3Path(ctx, comment)
if err != nil {
return "", err
return "", fmt.Errorf("convertForgejoAttachmentToF3Path convertForgejoCommentToF3Path: %w", err)
}
} else {
issue, err := issues.GetIssueByID(ctx, attachment.IssueID)
if err != nil {
return "", fmt.Errorf("GetIssueByID: %w", err)
return "", fmt.Errorf("convertForgejoAttachmentToF3Path GetIssueByID: %w", err)
}
attachablePath, err = convertForgejoIssueToF3Path(ctx, issue.IsPull, issue)
if err != nil {
return "", err
return "", fmt.Errorf("convertForgejoAttachmentToF3Path convertForgejoIssueToF3Path: %w", err)
}
}
} else if attachment.ReleaseID != 0 {
release, err := repo.GetReleaseByID(ctx, attachment.ReleaseID)
if err != nil {
return "", fmt.Errorf("GetReleaseByID: %w", err)
return "", fmt.Errorf("convertForgejoAttachmentToF3Path GetReleaseByID: %w", err)
}
attachablePath, err = convertForgejoReleaseToF3Path(ctx, release)
if err != nil {
return "", err
return "", fmt.Errorf("convertForgejoAttachmentToF3Path convertForgejoReleaseToF3Path: %w", err)
}
} else {
err := fmt.Errorf("unexpected attachment with IssueID == 0 and ReleaseID == 0 %+v", attachment)
err := fmt.Errorf("convertForgejoAttachmentToF3Path unexpected attachment with IssueID == 0 and ReleaseID == 0 %+v", attachment)
log.Error(err.Error())
return "", err
}
@ -140,20 +140,20 @@ func convertForgejoReactionToF3Path(ctx context.Context, reaction *issues.Reacti
if reaction.CommentID != 0 {
comment, err := issues.GetCommentByID(ctx, reaction.CommentID)
if err != nil {
return "", fmt.Errorf("GetCommentByID: %w", err)
return "", fmt.Errorf("convertForgejoReactionToF3Path GetCommentByID: %w", err)
}
reactionablePath, err = convertForgejoCommentToF3Path(ctx, comment)
if err != nil {
return "", err
return "", fmt.Errorf("convertForgejoReactionToF3Path convertForgejoCommentToF3Path: %w", err)
}
} else {
issue, err := issues.GetIssueByID(ctx, reaction.IssueID)
if err != nil {
return "", fmt.Errorf("GetIssueByID: %w", err)
return "", fmt.Errorf("convertForgejoReactionToF3Path GetIssueByID: %w", err)
}
reactionablePath, err = convertForgejoIssueToF3Path(ctx, issue.IsPull, issue)
if err != nil {
return "", err
return "", fmt.Errorf("convertForgejoReactionToF3Path convertForgejoIssueToF3Path: %w", err)
}
}
@ -163,11 +163,11 @@ func convertForgejoReactionToF3Path(ctx context.Context, reaction *issues.Reacti
func convertForgejoLabelToF3Path(ctx context.Context, label *issues.Label) (string, error) {
repository, err := repo.GetRepositoryByID(ctx, label.RepoID)
if err != nil {
return "", fmt.Errorf("GetRepositoryByID: %w", err)
return "", fmt.Errorf("convertForgejoLabelToF3Path GetRepositoryByID: %w", err)
}
projectPath, err := getF3PathOfRepository(ctx, repository)
if err != nil {
return "", err
return "", fmt.Errorf("convertForgejoLabelToF3Path getF3PathOfRepository: %w", err)
}
return f3_tree.NewLabelPathString(projectPath, f3_util.ToString(label.ID)), nil
}
@ -175,11 +175,11 @@ func convertForgejoLabelToF3Path(ctx context.Context, label *issues.Label) (stri
func convertForgejoMilestoneToF3Path(ctx context.Context, milestone *issues.Milestone) (string, error) {
repository, err := repo.GetRepositoryByID(ctx, milestone.RepoID)
if err != nil {
return "", fmt.Errorf("GetRepositoryByID: %w", err)
return "", fmt.Errorf("convertForgejoMilestoneToF3Path GetRepositoryByID: %w", err)
}
projectPath, err := getF3PathOfRepository(ctx, repository)
if err != nil {
return "", err
return "", fmt.Errorf("convertForgejoMilestoneToF3Path getF3PathOfRepository: %w", err)
}
return f3_tree.NewMilestonePathString(projectPath, f3_util.ToString(milestone.ID)), nil
}
@ -187,14 +187,14 @@ func convertForgejoMilestoneToF3Path(ctx context.Context, milestone *issues.Mile
func convertForgejoReviewToF3Path(ctx context.Context, review *issues.Review) (string, error) {
issue, err := issues.GetIssueByID(ctx, review.IssueID)
if err != nil {
return "", fmt.Errorf("GetIssueByID: %w", err)
return "", fmt.Errorf("convertForgejoReviewToF3Path GetIssueByID: %w", err)
}
if !issue.IsPull {
return "", fmt.Errorf("the issue %d of review %d must be a pull request", review.ID, issue.ID)
return "", fmt.Errorf("convertForgejoReviewToF3Path the issue %d of review %d must be a pull request", review.ID, issue.ID)
}
pullRequestPath, err := convertForgejoIssueToF3Path(ctx, issue.IsPull, issue)
if err != nil {
return "", err
return "", fmt.Errorf("convertForgejoReviewToF3Path convertForgejoIssueToF3Path: %w", err)
}
return f3_tree.NewReviewPathString(pullRequestPath, f3_util.ToString(review.ID)), nil
}
@ -228,7 +228,7 @@ func ConvertForgejoToF3Path(ctx context.Context, some any) (string, error) {
case *issues.Review:
return convertForgejoReviewToF3Path(ctx, o)
default:
err := fmt.Errorf("unexpected type %v %T when converting a Forgejo resource to a F3 path", some, some)
err := fmt.Errorf("ConvertForgejoToF3Path unexpected type %v %T when converting a Forgejo resource to a F3 path", some, some)
log.Error(err.Error())
return "", err
}