Skip to content

Commit

Permalink
Save error geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
irees committed Jan 10, 2024
1 parent 718839c commit 4eb806b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 32 deletions.
38 changes: 7 additions & 31 deletions actions/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@ import (
"os"

"github.com/interline-io/transitland-lib/tl"
"github.com/interline-io/transitland-lib/tl/causes"
"github.com/interline-io/transitland-lib/tl/tt"
"github.com/interline-io/transitland-lib/tlcsv"
"github.com/interline-io/transitland-lib/validator"
"github.com/interline-io/transitland-server/model"
)

type hasGeometries interface {
Geometries() []tt.Geometry
}

// ValidateUpload takes a file Reader and produces a validation package containing errors, warnings, file infos, service levels, etc.
func ValidateUpload(ctx context.Context, src io.Reader, feedURL *string, rturls []string) (*model.ValidationResult, error) {
cfg := model.ForContext(ctx)
Expand Down Expand Up @@ -124,21 +118,14 @@ func ValidateUpload(ctx context.Context, src io.Reader, feedURL *string, rturls
for _, err := range eg.Errors {
err2 := model.ValidationResultError{
Filename: eg.Filename,
EntityID: err.EntityID,
Message: err.Error(),
ErrorType: eg.ErrorType,
ErrorCode: eg.ErrorCode,
}
if v, ok := err.(hasContext); ok {
c := v.Context()
err2.EntityID = c.EntityID
err2.ErrorCode = c.Code
err2.Field = c.Field
}
if v, ok := err.(hasGeometries); ok {
for _, g := range v.Geometries() {
g := g
err2.Geometries = append(err2.Geometries, &g)
}
for _, gg := range err.Geometries {
gg := gg
err2.Geometries = append(err2.Geometries, &gg)
}
eg2.Errors = append(eg2.Errors, &err2)
}
Expand All @@ -161,20 +148,13 @@ func ValidateUpload(ctx context.Context, src io.Reader, feedURL *string, rturls
for _, err := range eg.Errors {
err2 := model.ValidationResultError{
Filename: eg.Filename,
EntityID: err.EntityID,
Message: err.Error(),
ErrorType: eg.ErrorType,
ErrorCode: eg.ErrorCode,
}
if v, ok := err.(hasContext); ok {
c := v.Context()
err2.EntityID = c.EntityID
err2.Field = c.Field
}
if v, ok := err.(hasGeometries); ok {
for _, g := range v.Geometries() {
g := g
err2.Geometries = append(err2.Geometries, &g)
}
for _, gg := range err.Geometries {
err2.Geometries = append(err2.Geometries, &gg)
}
eg2.Errors = append(eg2.Errors, &err2)
}
Expand Down Expand Up @@ -207,10 +187,6 @@ func ValidateUpload(ctx context.Context, src io.Reader, feedURL *string, rturls
return &result, nil
}

type hasContext interface {
Context() *causes.Context
}

func checkurl(address string) bool {
if address == "" {
return false
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/graph-gophers/dataloader/v7 v7.1.0
github.com/hypirion/go-filecache v0.0.0-20160810125507-e3e6ef6981f0
github.com/interline-io/log v0.0.0-20231211003339-8bdc406adcd2
github.com/interline-io/transitland-lib v0.14.1-0.20240109033825-0d199706b8eb
github.com/interline-io/transitland-lib v0.14.1-0.20240110033008-09a31a3ac942
github.com/interline-io/transitland-mw v0.0.0-20231220044449-a6aac07a9d9e
github.com/jellydator/ttlcache/v2 v2.11.1
github.com/jmoiron/sqlx v1.3.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ github.com/interline-io/log v0.0.0-20231211003339-8bdc406adcd2 h1:ScRM8Kr6UwAvbl
github.com/interline-io/log v0.0.0-20231211003339-8bdc406adcd2/go.mod h1:chJaM8SKcHI6ivoeFuZ8M8axTjSV4TPmuQ+sAyAHa34=
github.com/interline-io/transitland-lib v0.14.1-0.20240109033825-0d199706b8eb h1:TeyCU2enrDL40wGz4KujogH4gfzr4cuSyC2axdjM/Go=
github.com/interline-io/transitland-lib v0.14.1-0.20240109033825-0d199706b8eb/go.mod h1:TwGmZjX/iJRaYWKKosU/TIn8Dt4dywYCAXqmZwAA6qo=
github.com/interline-io/transitland-lib v0.14.1-0.20240110033008-09a31a3ac942 h1:YIwEMZTPbKFNkJi1Ij1J3g06h0d1TxEykjSbYhf7tgU=
github.com/interline-io/transitland-lib v0.14.1-0.20240110033008-09a31a3ac942/go.mod h1:TwGmZjX/iJRaYWKKosU/TIn8Dt4dywYCAXqmZwAA6qo=
github.com/interline-io/transitland-mw v0.0.0-20231220044449-a6aac07a9d9e h1:MZnYbL21CKMWQkNBaG6xnWjU7J7uXErlBM4RwXjIfRQ=
github.com/interline-io/transitland-mw v0.0.0-20231220044449-a6aac07a9d9e/go.mod h1:QyssKyKXwbTWhFT9O08nVj+gScPntMvLh1qMGNr1Ksw=
github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww=
Expand Down

0 comments on commit 4eb806b

Please sign in to comment.