From 4c7fccba038fef5c5fe951e61281ff5faa4fa0e0 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Thu, 2 Oct 2025 22:42:11 +0200 Subject: [PATCH] Improve error message for missing formats --- src/CliMonad.elm | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/CliMonad.elm b/src/CliMonad.elm index ac60517..edfca08 100644 --- a/src/CliMonad.elm +++ b/src/CliMonad.elm @@ -485,8 +485,13 @@ withFormat basicType maybeFormatName getter default = Just formatName -> CliMonad (\{ formats } -> + let + basicTypeName : String + basicTypeName = + Common.basicTypeToString basicType + in case - FastDict.get ( Common.basicTypeToString basicType, formatName ) formats + FastDict.get ( basicTypeName, formatName ) formats of Nothing -> let @@ -520,14 +525,34 @@ withFormat basicType maybeFormatName getter default = emptyOutput else + let + firstLine : String + firstLine = + "Don't know how to handle format \"" + ++ formatName + ++ "\" for type " + ++ Common.basicTypeToString basicType + ++ ", treating as the corresponding basic type." + + available : List String + available = + List.filterMap + (\( b, f ) -> + if b == basicTypeName then + Just f + + else + Nothing + ) + (FastDict.keys formats) + + secondLine : String + secondLine = + " Available formats: " ++ String.join ", " available + in { emptyOutput | warnings = - [ { message = - "Don't know how to handle format \"" - ++ formatName - ++ "\" for type " - ++ Common.basicTypeToString basicType - ++ ", treating as the corresponding basic type." + [ { message = firstLine ++ "\n" ++ secondLine , path = [ "format" ] } ]