Error out on empty UserSettings wrt #922

This commit is contained in:
Julian Ospald 2023-11-12 16:49:06 +08:00
parent ad9199568b
commit 9d223730de
No known key found for this signature in database
GPG Key ID: 4275CDA6A29BED43
2 changed files with 9 additions and 3 deletions

View File

@ -193,10 +193,14 @@ config configCommand settings userConf keybindings runLogger = case configComman
throwE $ ParseError "Empty values are not allowed"
Nothing -> do
usersettings <- decodeSettings k
when (usersettings == defaultUserSettings)
$ throwE $ ParseError ("Failed to parse setting (maybe typo?): " <> k)
lift $ doConfig usersettings
pure ()
Just v -> do
usersettings <- decodeSettings (k <> ": " <> v <> "\n")
when (usersettings == defaultUserSettings)
$ throwE $ ParseError ("Failed to parse key '" <> k <> "' with value '" <> v <> "' as user setting. Maybe typo?")
lift $ doConfig usersettings
pure ()
case r of
@ -204,7 +208,9 @@ config configCommand settings userConf keybindings runLogger = case configComman
VLeft (V (JSONDecodeError e)) -> do
runLogger $ logError $ "Error decoding config: " <> T.pack e
pure $ ExitFailure 65
VLeft _ -> pure $ ExitFailure 65
VLeft e -> do
runLogger (logError $ T.pack $ prettyHFError e)
pure $ ExitFailure 65
AddReleaseChannel force new -> do
r <- runE @'[DuplicateReleaseChannel] $ do

View File

@ -398,7 +398,7 @@ data UserSettings = UserSettings
, uPlatformOverride :: Maybe PlatformRequest
, uMirrors :: Maybe DownloadMirrors
}
deriving (Show, GHC.Generic)
deriving (Show, GHC.Generic, Eq)
defaultUserSettings :: UserSettings
defaultUserSettings = UserSettings Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
@ -459,7 +459,7 @@ data UserKeyBindings = UserKeyBindings
, kShowAll :: Maybe KeyCombination
, kShowAllTools :: Maybe KeyCombination
}
deriving (Show, GHC.Generic)
deriving (Show, GHC.Generic, Eq)
data KeyBindings = KeyBindings
{ bUp :: KeyCombination