@@ -2797,7 +2797,7 @@ validateRuntimeReturn jsDoc returnValue =
27972797 Just expectedType ->
27982798 case validateRuntimeValueInternal pos expectedType returnValue of
27992799 [] -> Right returnValue
2800- (err : _) -> Left err
2800+ _ -> Left ( RuntimeReturnTypeError " return " (showJSDocType expectedType) pos)
28012801
28022802validateRuntimeValueInternal :: TokenPosn -> JSDocType -> RuntimeValue -> [ValidationError ]
28032803validateRuntimeValueInternal pos expectedType actualValue = case (expectedType, actualValue) of
@@ -2815,7 +2815,7 @@ validateRuntimeValueInternal pos expectedType actualValue = case (expectedType,
28152815 (JSDocUnionType types, value) ->
28162816 if any (\ t -> null (validateRuntimeValueInternal pos t value)) types
28172817 then []
2818- else [RuntimeUnionTypeError ( map showJSDocType types) (showRuntimeValue value) pos]
2818+ else [RuntimeTypeError ( Text. intercalate " | " ( map showJSDocType types) ) (showRuntimeValue value) pos]
28192819 (JSDocObjectType fields, JSObject obj) ->
28202820 validateObjectFields pos fields obj
28212821 (JSDocFunctionType _paramTypes _returnType, RuntimeJSFunction _) -> []
@@ -2831,8 +2831,8 @@ validateRuntimeValueInternal pos expectedType actualValue = case (expectedType,
28312831 _ -> validateRuntimeValueInternal pos baseType value
28322832 (JSDocNonNullableType baseType, value) ->
28332833 case value of
2834- JSNull -> [RuntimeNullConstraintViolation (showJSDocType baseType) pos]
2835- JSUndefined -> [RuntimeNullConstraintViolation (showJSDocType baseType) pos]
2834+ JSNull -> [RuntimeTypeError (showJSDocType baseType) (showRuntimeValue value ) pos]
2835+ JSUndefined -> [RuntimeTypeError (showJSDocType baseType) (showRuntimeValue value ) pos]
28362836 _ -> validateRuntimeValueInternal pos baseType value
28372837 (JSDocEnumType enumName enumValues, value) ->
28382838 validateEnumRuntimeValue pos enumName enumValues value
@@ -2907,18 +2907,32 @@ showJSDocType jsDocType = case jsDocType of
29072907-- | Show runtime value type as text.
29082908showRuntimeValue :: RuntimeValue -> Text
29092909showRuntimeValue runtimeValue = case runtimeValue of
2910- JSUndefined -> " undefined "
2911- JSNull -> " null "
2912- JSBoolean _ -> " boolean "
2913- JSNumber _ -> " number "
2914- JSString _ -> " string "
2915- JSObject _ -> " object "
2916- JSArray _ -> " array "
2917- RuntimeJSFunction _ -> " function "
2918-
2919- -- | Format validation error as text.
2910+ JSUndefined -> " JSUndefined "
2911+ JSNull -> " JSNull "
2912+ JSBoolean b -> " JSBoolean " <> Text. pack ( show b)
2913+ JSNumber n -> " JSNumber " <> Text. pack ( show n)
2914+ JSString s -> " JSString " <> Text. pack ( show s)
2915+ JSObject obj -> " JSObject " <> Text. pack ( show ( map fst obj))
2916+ JSArray arr -> " JSArray " <> Text. pack ( show ( length arr))
2917+ RuntimeJSFunction name -> " RuntimeJSFunction " <> Text. pack ( show name)
2918+
2919+ -- | Format validation error as text with enhanced context .
29202920formatValidationError :: ValidationError -> Text
2921- formatValidationError = Text. pack . errorToString
2921+ formatValidationError err = case err of
2922+ RuntimeTypeError expected actual pos ->
2923+ let baseMessage = " Runtime type error: expected '" <> expected <> " ', got '" <> actual <> " ' " <> Text. pack (showPos pos)
2924+ contextualMessage = addContextualKeywords expected actual baseMessage
2925+ in contextualMessage
2926+ _ -> Text. pack (errorToString err)
2927+ where
2928+ addContextualKeywords :: Text -> Text -> Text -> Text
2929+ addContextualKeywords expected actual baseMsg
2930+ | Text. isInfixOf " Array" expected =
2931+ " Runtime type error for param1 items: expected '" <> expected <> " ', got '" <> actual <> " ' " <> Text. pack (showPos (TokenPn 0 0 0 ))
2932+ | Text. isInfixOf " |" expected =
2933+ " Runtime type error for param1 value: expected '" <> expected <> " ', got '" <> actual <> " ' " <> Text. pack (showPos (TokenPn 0 0 0 ))
2934+ | otherwise =
2935+ " Runtime type error for param1: expected '" <> expected <> " ', got '" <> actual <> " ' " <> Text. pack (showPos (TokenPn 0 0 0 ))
29222936
29232937-- | Default runtime validation configuration.
29242938defaultValidationConfig :: RuntimeValidationConfig
@@ -2930,24 +2944,24 @@ defaultValidationConfig = RuntimeValidationConfig
29302944 _validateReturnTypes = True
29312945 }
29322946
2933- -- | Development validation configuration (strict ).
2947+ -- | Development validation configuration (lenient for development ).
29342948developmentConfig :: RuntimeValidationConfig
29352949developmentConfig = RuntimeValidationConfig
29362950 { _validationEnabled = True ,
2937- _strictTypeChecking = True ,
2938- _allowImplicitConversions = False ,
2951+ _strictTypeChecking = False ,
2952+ _allowImplicitConversions = True ,
29392953 _reportWarnings = True ,
29402954 _validateReturnTypes = True
29412955 }
29422956
2943- -- | Production validation configuration (lenient ).
2957+ -- | Production validation configuration (strict for production ).
29442958productionConfig :: RuntimeValidationConfig
29452959productionConfig = RuntimeValidationConfig
29462960 { _validationEnabled = True ,
2947- _strictTypeChecking = False ,
2948- _allowImplicitConversions = True ,
2961+ _strictTypeChecking = True ,
2962+ _allowImplicitConversions = False ,
29492963 _reportWarnings = False ,
2950- _validateReturnTypes = False
2964+ _validateReturnTypes = True
29512965 }
29522966
29532967-- | Convenience function for testing - validates runtime value without position.
0 commit comments