summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-11-19 23:01:43 (GMT)
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-11-23 23:57:49 (GMT)
commitcb11fcb52ce8d5d1473a380db5fc0d32bf8ae75c (patch)
tree8640b62fe979e11a3a35dc167745f90b51dd20d8
parent0e6c204570f77950c9019faa50ff867c158249c5 (diff)
downloadghc-cb11fcb52ce8d5d1473a380db5fc0d32bf8ae75c.zip
ghc-cb11fcb52ce8d5d1473a380db5fc0d32bf8ae75c.tar.gz
ghc-cb11fcb52ce8d5d1473a380db5fc0d32bf8ae75c.tar.bz2
Packages: Don't use expectJust
Throw a slightly more informative error on failure. Motivated by the errors seen in !2160.
-rw-r--r--compiler/main/Packages.hs13
1 files changed, 8 insertions, 5 deletions
diff --git a/compiler/main/Packages.hs b/compiler/main/Packages.hs
index f5a8c96..baed7f5 100644
--- a/compiler/main/Packages.hs
+++ b/compiler/main/Packages.hs
@@ -428,9 +428,11 @@ extendPackageConfigMap (PackageConfigMap pkg_map closure) new_pkgs
-- | Looks up the package with the given id in the package state, panicing if it is
-- not found
-getPackageDetails :: DynFlags -> UnitId -> PackageConfig
+getPackageDetails :: HasDebugCallStack => DynFlags -> UnitId -> PackageConfig
getPackageDetails dflags pid =
- expectJust "getPackageDetails" (lookupPackage dflags pid)
+ case lookupPackage dflags pid of
+ Just config -> config
+ Nothing -> pprPanic "getPackageDetails" (ppr pid)
lookupInstalledPackage :: DynFlags -> InstalledUnitId -> Maybe PackageConfig
lookupInstalledPackage dflags uid = lookupInstalledPackage' (pkgIdMap (pkgState dflags)) uid
@@ -438,10 +440,11 @@ lookupInstalledPackage dflags uid = lookupInstalledPackage' (pkgIdMap (pkgState
lookupInstalledPackage' :: PackageConfigMap -> InstalledUnitId -> Maybe PackageConfig
lookupInstalledPackage' (PackageConfigMap db _) uid = lookupUDFM db uid
-getInstalledPackageDetails :: DynFlags -> InstalledUnitId -> PackageConfig
+getInstalledPackageDetails :: HasDebugCallStack => DynFlags -> InstalledUnitId -> PackageConfig
getInstalledPackageDetails dflags uid =
- expectJust "getInstalledPackageDetails" $
- lookupInstalledPackage dflags uid
+ case lookupInstalledPackage dflags uid of
+ Just config -> config
+ Nothing -> pprPanic "getInstalledPackageDetails" (ppr uid)
-- | Get a list of entries from the package database. NB: be careful with
-- this function, although all packages in this map are "visible", this