on master help sign in
Add: better parsing errors
bdb096dDenis Redozubov
src/Data/Schematic/Schema.hs+6−6
@@ -454,22 +454,22 @@ instance SingI schema => J.FromJSON (JsonRepr schema) where
454 fieldRepr <- case s of
454 fieldRepr <- case s of
455 SSchemaText so -> case H.lookup fieldName h of
455 SSchemaText so -> case H.lookup fieldName h of
456 Just v -> withSingI so $ FieldRepr <$> parseJSON v
456 Just v -> withSingI so $ FieldRepr <$> parseJSON v
457− Nothing -> fail "schematext"
457+ Nothing -> fail $ "No text field: " P.++ show fieldName
458 SSchemaNumber so -> case H.lookup fieldName h of
458 SSchemaNumber so -> case H.lookup fieldName h of
459 Just v -> withSingI so $ FieldRepr <$> parseJSON v
459 Just v -> withSingI so $ FieldRepr <$> parseJSON v
460− Nothing -> fail "schemanumber"
460+ Nothing -> fail $ "No number field: " P.++ show fieldName
461 SSchemaBoolean -> case H.lookup fieldName h of
461 SSchemaBoolean -> case H.lookup fieldName h of
462 Just v -> FieldRepr <$> parseJSON v
462 Just v -> FieldRepr <$> parseJSON v
463− Nothing -> fail "schemaboolean"
463+ Nothing -> fail $ "No boolean field: " P.++ show fieldName
464 SSchemaNull -> case H.lookup fieldName h of
464 SSchemaNull -> case H.lookup fieldName h of
465 Just v -> FieldRepr <$> parseJSON v
465 Just v -> FieldRepr <$> parseJSON v
466− Nothing -> fail "schemanull"
466+ Nothing -> fail $ "No null field: " P.++ show fieldName
467 SSchemaArray sa sb -> case H.lookup fieldName h of
467 SSchemaArray sa sb -> case H.lookup fieldName h of
468 Just v -> withSingI sa $ withSingI sb $ FieldRepr <$> parseJSON v
468 Just v -> withSingI sa $ withSingI sb $ FieldRepr <$> parseJSON v
469− Nothing -> fail "schemaarray"
469+ Nothing -> fail $ "No array field: " P.++ show fieldName
470 SSchemaObject so -> case H.lookup fieldName h of
470 SSchemaObject so -> case H.lookup fieldName h of
471 Just v -> withSingI so $ FieldRepr <$> parseJSON v
471 Just v -> withSingI so $ FieldRepr <$> parseJSON v
472− Nothing -> fail "schemaobject"
472+ Nothing -> fail $ "No object field" P.++ show fieldName
473 SSchemaOptional so -> case H.lookup fieldName h of
473 SSchemaOptional so -> case H.lookup fieldName h of
474 Just v -> withSingI so $ FieldRepr <$> parseJSON v
474 Just v -> withSingI so $ FieldRepr <$> parseJSON v
475 Nothing -> withSingI so $ pure $ FieldRepr $ ReprOptional Nothing
475 Nothing -> withSingI so $ pure $ FieldRepr $ ReprOptional Nothing