From cb11fcb52ce8d5d1473a380db5fc0d32bf8ae75c Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Tue, 19 Nov 2019 18:01:43 -0500 Subject: Packages: Don't use expectJust Throw a slightly more informative error on failure. Motivated by the errors seen in !2160. --- compiler/main/Packages.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/main/Packages.hs b/compiler/main/Packages.hs index f5a8c964b3..baed7f5ec1 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 -- cgit v1.2.1