Monorepo for Tangled tangled.org
766
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview: bubble up error on `PullFromRecord`

Signed-off-by: Seongmin Lee <git@boltless.me>

authored by

Seongmin Lee and committed by tangled.org f4d9946e 9da1b4ae

+29 -19
+6 -3
appview/ingester.go
··· 1046 1046 } 1047 1047 }() 1048 1048 1049 - pull := models.PullFromRecord(did, rkey, record, readers) 1050 - if err := i.Validator.ValidatePull(&pull); err != nil { 1049 + pull, err := models.PullFromRecord(did, rkey, record, readers) 1050 + if err != nil { 1051 + return fmt.Errorf("failed to parse pull from record: %w", err) 1052 + } 1053 + if err := i.Validator.ValidatePull(pull); err != nil { 1051 1054 return fmt.Errorf("failed to validate pull: %w", err) 1052 1055 } 1053 1056 ··· 1058 1061 } 1059 1062 defer tx.Rollback() 1060 1063 1061 - err = db.PutPull(tx, &pull) 1064 + err = db.PutPull(tx, pull) 1062 1065 if err != nil { 1063 1066 l.Error("failed to create pull", "err", err) 1064 1067 return err
+23 -16
appview/models/pull.go
··· 133 133 } 134 134 } 135 135 136 - func PullFromRecord(did, rkey string, record tangled.RepoPull, blobs []*io.ReadCloser) Pull { 136 + func PullFromRecord(did, rkey string, record tangled.RepoPull, blobs []*io.ReadCloser) (*Pull, error) { 137 137 created, err := time.Parse(time.RFC3339, record.CreatedAt) 138 138 if err != nil { 139 - created = time.Now() 139 + return nil, fmt.Errorf("invalid createdAt: %w", err) 140 140 } 141 141 142 142 body := "" ··· 155 155 var targetBranch string 156 156 if record.Target != nil { 157 157 if record.Target.Repo != nil { 158 - if uri, err := syntax.ParseATURI(*record.Target.Repo); err == nil { 159 - targetRepoAt = uri 158 + uri, err := syntax.ParseATURI(*record.Target.Repo) 159 + if err != nil { 160 + return nil, fmt.Errorf("invalid target.repo aturi: %w", err) 160 161 } 162 + targetRepoAt = uri 161 163 } 162 164 targetBranch = record.Target.Branch 163 165 } ··· 169 171 } 170 172 171 173 if record.Source.Repo != nil { 172 - if uri, err := syntax.ParseATURI(*record.Source.Repo); err == nil { 173 - pullSource.RepoAt = &uri 174 + uri, err := syntax.ParseATURI(*record.Source.Repo) 175 + if err != nil { 176 + return nil, fmt.Errorf("invalid source.repo aturi: %w", err) 174 177 } 178 + pullSource.RepoAt = &uri 175 179 } 176 180 if record.Source.RepoDid != nil { 177 - if did, err := syntax.ParseDID(*record.Source.RepoDid); err != nil { 178 - pullSource.RepoDid = &did 181 + did, err := syntax.ParseDID(*record.Source.RepoDid) 182 + if err != nil { 183 + return nil, fmt.Errorf("invalid source.repoDid did: %w", err) 179 184 } 185 + pullSource.RepoDid = &did 180 186 } 181 187 } 182 188 183 189 var dependentOn *syntax.ATURI 184 190 if record.DependentOn != nil { 185 - if uri, err := syntax.ParseATURI(*record.DependentOn); err == nil { 186 - dependentOn = &uri 191 + uri, err := syntax.ParseATURI(*record.DependentOn) 192 + if err != nil { 193 + return nil, fmt.Errorf("invalid dependentOn aturi: %w", err) 187 194 } 195 + dependentOn = &uri 188 196 } 189 197 190 198 var submissions []*PullSubmission ··· 195 203 } 196 204 submission, err := PullSubmissionFromRecord(did, rkey, i, s, blob) 197 205 if err != nil { 198 - submissions = append(submissions, nil) 199 - } else { 200 - submissions = append(submissions, submission) 206 + return nil, fmt.Errorf("invalid pull round at index %d: %w", i, err) 201 207 } 208 + submissions = append(submissions, submission) 202 209 } 203 210 204 - return Pull{ 211 + return &Pull{ 205 212 RepoAt: targetRepoAt, 206 213 OwnerDid: did, 207 214 Rkey: rkey, ··· 213 220 Submissions: submissions, 214 221 Created: created, 215 222 DependentOn: dependentOn, 216 - } 223 + }, nil 217 224 } 218 225 219 226 func PullSubmissionFromRecord(did, rkey string, roundNumber int, round *tangled.RepoPull_Round, blob *io.ReadCloser) (*PullSubmission, error) { 220 227 created, err := time.Parse(time.RFC3339, round.CreatedAt) 221 228 if err != nil { 222 - created = time.Now() 229 + return nil, fmt.Errorf("invalid createdAt: %w", err) 223 230 } 224 231 225 232 var patch, sourceRev string