Skip to content

Commit

Permalink
Merge pull request #348 from snyk/fix/better-future-error
Browse files Browse the repository at this point in the history
fix: report better error when building future versions
  • Loading branch information
jgresty authored Jun 19, 2024
2 parents f219b3f + a2b8f7c commit 53cbbbf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 8 additions & 0 deletions internal/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"path/filepath"
"time"

"github.com/getkin/kin-openapi/openapi3"
"github.com/ghodss/yaml"
Expand Down Expand Up @@ -165,6 +166,13 @@ func (c *Compiler) Build(ctx context.Context, apiName string) error {
}
versions := specVersions.Versions()
for _, version := range versions {
if version.LifecycleAt(time.Now()) == vervet.LifecycleUnreleased {
return buildErr(fmt.Errorf(
"API spec with version %s is in the future. This is not supported as it may cause breakage",
version,
))
}

spec, err := specVersions.At(version)
if err == vervet.ErrNoMatchingVersion {
continue
Expand Down
2 changes: 2 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ func (l Lifecycle) String() string {
return "deprecated"
case LifecycleSunset:
return "sunset"
case LifecycleUnreleased:
return "unreleased"
default:
panic(fmt.Sprintf("invalid lifecycle (%d)", int(l)))
}
Expand Down
10 changes: 0 additions & 10 deletions version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,3 @@ func TestLifecycleAtDefaultDate(t *testing.T) {
})
}
}

func TestLifecycleAtUnreleasedVersionStringPanics(t *testing.T) {
c := qt.New(t)
c.Patch(TimeNow, func() time.Time { return time.Date(2022, time.June, 6, 14, 49, 50, 0, time.UTC) })
version := MustParseVersion("2022-10-16~wip")
lifecycle := version.LifecycleAt(time.Time{})
c.Assert(func() {
c.Log(lifecycle.String())
}, qt.PanicMatches, "invalid lifecycle.*")
}

0 comments on commit 53cbbbf

Please sign in to comment.