Skip to content

Commit

Permalink
Pass through additional context for RT errors
Browse files Browse the repository at this point in the history
  • Loading branch information
irees committed Dec 1, 2023
1 parent 795d2d8 commit 24af2a5
Show file tree
Hide file tree
Showing 10 changed files with 590 additions and 93 deletions.
32 changes: 28 additions & 4 deletions actions/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import (

"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/auth/authn"
"github.com/interline-io/transitland-server/config"
"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, cfg config.Config, src io.Reader, feedURL *string, rturls []string, user authn.User) (*model.ValidationResult, error) {
// Check inputs
Expand Down Expand Up @@ -109,18 +114,31 @@ func ValidateUpload(ctx context.Context, cfg config.Config, src io.Reader, feedU
}
eg2 := model.ValidationResultErrorGroup{
Filename: eg.Filename,
Field: eg.Field,
ErrorCode: eg.ErrorCode,
ErrorType: eg.ErrorType,
Message: eg.Message,
Count: eg.Count,
Limit: eg.Limit,
}
for _, err := range eg.Errors {
err2 := model.ValidationResultError{
Filename: eg.Filename,
Message: err.Error(),
Filename: eg.Filename,
Message: err.Error(),
ErrorType: eg.ErrorType,
ErrorCode: eg.ErrorCode,
}
if v, ok := err.(hasGeometries); ok {
for _, g := range v.Geometries() {
g := g
err2.Geometries = append(err2.Geometries, &g)
}
}

if v, ok := err.(hasContext); ok {
c := v.Context()
err2.EntityID = c.EntityID
err2.ErrorCode = c.Code
err2.Field = c.Field
}
eg2.Errors = append(eg2.Errors, &err2)
Expand All @@ -133,14 +151,20 @@ func ValidateUpload(ctx context.Context, cfg config.Config, src io.Reader, feedU
}
eg2 := model.ValidationResultErrorGroup{
Filename: eg.Filename,
Field: eg.Field,
ErrorCode: eg.ErrorCode,
ErrorType: eg.ErrorType,
Message: eg.Message,
Count: eg.Count,
Limit: eg.Limit,
}

for _, err := range eg.Errors {
err2 := model.ValidationResultError{
Filename: eg.Filename,
Message: err.Error(),
Filename: eg.Filename,
Message: err.Error(),
ErrorType: eg.ErrorType,
ErrorCode: eg.ErrorCode,
}
if v, ok := err.(hasContext); ok {
c := v.Context()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551
github.com/graph-gophers/dataloader/v7 v7.1.0
github.com/hypirion/go-filecache v0.0.0-20160810125507-e3e6ef6981f0
github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231122224424-d95957e76b4e
github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231201022717-a7acfe4abe4b
github.com/jellydator/ttlcache/v2 v2.11.1
github.com/jmoiron/sqlx v1.3.5
github.com/lib/pq v1.10.7
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6
github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231122224424-d95957e76b4e h1:y24HWm0yVrlwE9a8oM+vKLDDW5F/zco/lFB+qX9Fx3I=
github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231122224424-d95957e76b4e/go.mod h1:UcfuCX6DyKt/yn5GECFn3jQ6NcZEjt5XyPjf8a3tXZ4=
github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231130233906-2adb3bfd1d44 h1:kRFPzcrs2SihxsTu+hOVTCRIICw6p+A2HlR9LzvXX6w=
github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231130233906-2adb3bfd1d44/go.mod h1:UcfuCX6DyKt/yn5GECFn3jQ6NcZEjt5XyPjf8a3tXZ4=
github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231201022717-a7acfe4abe4b h1:2O4SNVGuxBCQDwxC1oyiJSTWmfLytQJwO9ZokE1n5Yg=
github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231201022717-a7acfe4abe4b/go.mod h1:UcfuCX6DyKt/yn5GECFn3jQ6NcZEjt5XyPjf8a3tXZ4=
github.com/jarcoal/httpmock v1.3.0 h1:2RJ8GP0IIaWwcC9Fp2BmVi8Kog3v2Hn7VXM3fTd+nuc=
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4=
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag=
Expand Down
Loading

0 comments on commit 24af2a5

Please sign in to comment.