Skip to content

Commit 6f44ef1

Browse files
committed
Better handle ttl = 0.
1 parent 32c486d commit 6f44ef1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

libs/wire-api/src/Wire/API/Team/Feature.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,12 @@ data FeatureTTL
354354
= FeatureTTLSeconds Word
355355
| FeatureTTLUnlimited
356356
deriving stock (Eq, Show, Generic)
357-
deriving (Arbitrary) via (GenericUniform FeatureTTL)
357+
358+
instance Arbitrary FeatureTTL where
359+
arbitrary = nonZero <$> arbitrary
360+
where
361+
nonZero 0 = FeatureTTLUnlimited
362+
nonZero n = FeatureTTLSeconds n
358363

359364
instance ToSchema FeatureTTL where
360365
schema = mkSchema ttlDoc toTTL fromTTL
@@ -376,9 +381,9 @@ instance ToSchema FeatureTTL where
376381
parseSeconds :: A.Value -> A.Parser FeatureTTL
377382
parseSeconds = A.withScientific "FeatureTTL" $
378383
\s -> case toBoundedInteger s of
379-
Just 0 -> pure FeatureTTLUnlimited
384+
Just 0 -> A.parseFail "Expected a positive integer. Got 0 instead."
380385
Just i -> pure . FeatureTTLSeconds $ i
381-
Nothing -> A.parseFail "Expected an integer."
386+
Nothing -> A.parseFail "Expected an positive integer."
382387

383388
fromTTL :: FeatureTTL -> Maybe A.Value
384389
fromTTL FeatureTTLUnlimited = Just "unlimited"

0 commit comments

Comments
 (0)