From 5ca5bbde186c611c73351b9cc5fb8172756ee93b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Thu, 30 Jan 2025 10:42:19 +0100 Subject: [PATCH] fix(#1841): fix unhandled missing index exception --- CHANGELOG.md | 1 + govtool/backend/src/VVA/API/Types.hs | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfc882128..848e5b4fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ changes. ### Fixed - Fix displaying DRep with doNotList property as string +- Handle exception when no index is provided to /proposal/get endpoint [Issue 1841](https://github.com/IntersectMBO/govtool/issues/1841) ### Changed diff --git a/govtool/backend/src/VVA/API/Types.hs b/govtool/backend/src/VVA/API/Types.hs index 3341f4860..2181bd676 100644 --- a/govtool/backend/src/VVA/API/Types.hs +++ b/govtool/backend/src/VVA/API/Types.hs @@ -139,11 +139,14 @@ instance ToJSON GovActionId where instance FromHttpApiData GovActionId where parseUrlPiece t = case Text.splitOn "#" t of [hash, rest] -> do - index <- case readMaybe $ Text.unpack rest of - Just x -> pure x - _ -> Left (Text.tail rest <> " is not a number") - hexHash <- parseUrlPiece hash - Right $ GovActionId hexHash index + if Text.null rest + then Left "Missing index in hash#index format" + else do + index <- case readMaybe $ Text.unpack rest of + Just x -> pure x + _ -> Left (rest <> " is not a number") + hexHash <- parseUrlPiece hash + Right $ GovActionId hexHash index _ -> Left "Not a valid hash#index value" exampleGovActionId :: Text