@@ -402,7 +402,7 @@ deriveSerializeWith conf mDecs = do
402402 dec <- mDecs
403403 case dec of
404404 [inst@(InstanceD _ _ headTy [])] -> do
405− dt <- reifyDataType (getMainTypeName headTy)
405+ dt <- reifyDataType (getMainTypeName dec headTy)
406406 let cons = dtCons dt
407407 deriveSerializeInternal conf headTy cons (next inst)
408408 _ -> errorUnsupported
@@ -412,14 +412,31 @@ deriveSerializeWith conf mDecs = do
412412 pure [InstanceD mo preds headTy methods]
413413 next _ _ = errorUnsupported
414414
415− getMainTypeName = go . unwrap
416−
417− unwrap (AppT (ConT _) r) = r
418− unwrap _ = error "getMainTypeName.unwrap: Undefined instance declaration."
419−
420− go (ConT nm) = nm
421− go (AppT l _) = go l
422− go _ = error "getMainTypeName.go: Undefined instance declaration."
415+ errorMessage dec =
416+ error $ unlines
417+ [ "Error: deriveSerializeWith:"
418+ , ""
419+ , ">> " ++ pprint dec
420+ , ""
421+ , "The above is not a valid instance declaration."
422+ , "Any haskell instance declaration without a body is valid."
423+ , ""
424+ , "Examples:"
425+ , "instance Serialize (Proxy a)"
426+ , "instance Serialize a => Serialize (Identity a)"
427+ , "instance Serialize (TableT Identity)"
428+ ]
429+
430+ getMainTypeName dec = go . unwrap
431+
432+ where
433+
434+ unwrap (AppT (ConT _) r) = r
435+ unwrap _ = errorMessage dec
436+
437+ go (ConT nm) = nm
438+ go (AppT l _) = go l
439+ go _ = errorMessage dec
423440
424441
425442-- | Template haskell helper to create instances of 'Serialize' automatically.