diff --git a/appview/ingester.go b/appview/ingester.go --- a/appview/ingester.go +++ b/appview/ingester.go @@ -1046,8 +1046,11 @@ } } }() - pull := models.PullFromRecord(did, rkey, record, readers) - if err := i.Validator.ValidatePull(&pull); err != nil { + pull, err := models.PullFromRecord(did, rkey, record, readers) + if err != nil { + return fmt.Errorf("failed to parse pull from record: %w", err) + } + if err := i.Validator.ValidatePull(pull); err != nil { return fmt.Errorf("failed to validate pull: %w", err) } @@ -1058,7 +1061,7 @@ return err } defer tx.Rollback() - err = db.PutPull(tx, &pull) + err = db.PutPull(tx, pull) if err != nil { l.Error("failed to create pull", "err", err) return err diff --git a/appview/models/pull.go b/appview/models/pull.go --- a/appview/models/pull.go +++ b/appview/models/pull.go @@ -133,10 +133,10 @@ DependentOn: dependentOn, } } -func PullFromRecord(did, rkey string, record tangled.RepoPull, blobs []*io.ReadCloser) Pull { +func PullFromRecord(did, rkey string, record tangled.RepoPull, blobs []*io.ReadCloser) (*Pull, error) { created, err := time.Parse(time.RFC3339, record.CreatedAt) if err != nil { - created = time.Now() + return nil, fmt.Errorf("invalid createdAt: %w", err) } body := "" @@ -155,9 +155,11 @@ var targetRepoAt syntax.ATURI var targetBranch string if record.Target != nil { if record.Target.Repo != nil { - if uri, err := syntax.ParseATURI(*record.Target.Repo); err == nil { - targetRepoAt = uri + uri, err := syntax.ParseATURI(*record.Target.Repo) + if err != nil { + return nil, fmt.Errorf("invalid target.repo aturi: %w", err) } + targetRepoAt = uri } targetBranch = record.Target.Branch } @@ -169,22 +171,28 @@ Branch: record.Source.Branch, } if record.Source.Repo != nil { - if uri, err := syntax.ParseATURI(*record.Source.Repo); err == nil { - pullSource.RepoAt = &uri + uri, err := syntax.ParseATURI(*record.Source.Repo) + if err != nil { + return nil, fmt.Errorf("invalid source.repo aturi: %w", err) } + pullSource.RepoAt = &uri } if record.Source.RepoDid != nil { - if did, err := syntax.ParseDID(*record.Source.RepoDid); err != nil { - pullSource.RepoDid = &did + did, err := syntax.ParseDID(*record.Source.RepoDid) + if err != nil { + return nil, fmt.Errorf("invalid source.repoDid did: %w", err) } + pullSource.RepoDid = &did } } var dependentOn *syntax.ATURI if record.DependentOn != nil { - if uri, err := syntax.ParseATURI(*record.DependentOn); err == nil { - dependentOn = &uri + uri, err := syntax.ParseATURI(*record.DependentOn) + if err != nil { + return nil, fmt.Errorf("invalid dependentOn aturi: %w", err) } + dependentOn = &uri } var submissions []*PullSubmission @@ -195,13 +203,12 @@ blob = blobs[i] } submission, err := PullSubmissionFromRecord(did, rkey, i, s, blob) if err != nil { - submissions = append(submissions, nil) - } else { - submissions = append(submissions, submission) + return nil, fmt.Errorf("invalid pull round at index %d: %w", i, err) } + submissions = append(submissions, submission) } - return Pull{ + return &Pull{ RepoAt: targetRepoAt, OwnerDid: did, Rkey: rkey, @@ -213,13 +220,13 @@ State: PullOpen, Submissions: submissions, Created: created, DependentOn: dependentOn, - } + }, nil } func PullSubmissionFromRecord(did, rkey string, roundNumber int, round *tangled.RepoPull_Round, blob *io.ReadCloser) (*PullSubmission, error) { created, err := time.Parse(time.RFC3339, round.CreatedAt) if err != nil { - created = time.Now() + return nil, fmt.Errorf("invalid createdAt: %w", err) } var patch, sourceRev string