summaryrefslogtreecommitdiff
path: root/src/Propellor/Types.hs
diff options
context:
space:
mode:
authorJoey Hess2019-07-01 18:27:48 -0400
committerJoey Hess2019-07-01 22:06:21 -0400
commitde21ef26861db458b0dfb0212cf501f9f8ed459b (patch)
tree474b1e9ae6874368d5489c0906ae05d28eb077e7 /src/Propellor/Types.hs
parent14f6ae30809d8bbdb10b91cc59757e865a365df8 (diff)
optionally use type-errors to detect stuckness
Use the type-errors library to detect when the type checker gets stuck unable to reduce type-level operations on MetaTypes, and avoid displaying massive error messages in such a case. But, since type-errors is a new library not available in eg Debian yet, added a WithTypeErrors build flag. When the library is not available, cabal will automatically disable that build flag, and it will build without the type-errors library. This is most often used when combining properties of different types. If the MetaTypes don't have an OS in common, the error message used to be "Property " followed by pages of MetaTypes operations. Now it looks like this: • Cannot combine Properties: Property <unknown> Property HasInfo + Debian + Buntish + ArchLinux + FreeBSD (Property <unknown> is often due to a partially applied Property constructor, or due to passing the wrong type to a Property constructor.) Also it's used in ensureProperty to detect a case where the outer MetaTypes need to be inferred in order to check if the inner MetaTypes match, but the type checker is unable to infer it: • ensureProperty outer Property type is not able to be inferred here. Consider adding a type annotation. • When checking the inferred type writeConfig :: forall (outer :: [Propellor.Types.MetaTypes.MetaType]) t. And it's used in tightenTargets to detect when ghc is unable to infer the desired type of Property: • Unable to infer desired Property type in this use of tightenTargets. Consider adding a type annotation. • When checking the inferred type mk :: forall (tightened :: [Propellor.Types.MetaTypes.MetaType]).
Diffstat (limited to 'src/Propellor/Types.hs')
-rw-r--r--src/Propellor/Types.hs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/Propellor/Types.hs b/src/Propellor/Types.hs
index e8e92332..026babf0 100644
--- a/src/Propellor/Types.hs
+++ b/src/Propellor/Types.hs
@@ -224,9 +224,16 @@ type family TightenTargetsAllowed untightened tightened where
If (Targets tightened `IsSubset` Targets untightened
&& NonTargets untightened `IsSubset` NonTargets tightened)
'True
- ( TypeError
- ( 'Text "This use of tightenTargets would widen, not narrow, adding: "
- ':$$: PrettyPrintMetaTypes (Difference (Targets tightened) (Targets untightened))
+ (IfStuck (Targets tightened)
+ (TypeError
+ ('Text "Unable to infer desired Property type in this use of tightenTargets."
+ ':$$: ('Text "Consider adding a type annotation.")
+ )
+ )
+ (TypeError
+ ('Text "This use of tightenTargets would widen, not narrow, adding: "
+ ':$$: PrettyPrintMetaTypes (Difference (Targets tightened) (Targets untightened))
+ )
)
)