From ffdf4af243efdaf8f75147012d9348a4c7c4a07b Mon Sep 17 00:00:00 2001 From: Chris Done Date: Fri, 22 May 2015 11:32:57 +0200 Subject: [PATCH] Generalize stripDir to MonadThrow --- src/Path.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Path.hs b/src/Path.hs index 3951980..e7e8960 100644 --- a/src/Path.hs +++ b/src/Path.hs @@ -239,9 +239,14 @@ toFilePath (Path l) = l -- -- In other words the bases must match. -- -stripDir :: Path b Dir -> Path b t -> Maybe (Path Rel t) +-- Throws: 'Couldn'tStripPrefixDir' +-- +stripDir :: MonadThrow m + => Path b Dir -> Path b t -> m (Path Rel t) stripDir (Path p) (Path l) = - fmap Path (stripPrefix p l) + case fmap Path (stripPrefix p l) of + Nothing -> throwM (Couldn'tStripPrefixDir p l) + Just ok -> return ok -- | Is p a parent of the given location? Implemented in terms of -- 'stripDir'. The bases must match.