Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix fromJust crash #116

Merged
merged 2 commits into from

2 participants

@nh2
nh2 commented

For it is evil and causes grievance ;)

@nh2
nh2 commented

Note: Don't crash on empty cabal file really only removes the crash, but this isn't enough yet.

When I have an empty cabal file, I get

Tools/Foo/Main.hs:1:1:Could not find module `Prelude'It is a member of the hidden package `base'.Perhaps you need to add `base' to the build-depends in your .cabal file.It is a member of the hidden package `haskell98-2.0.0.2'.Perhaps you need to add `haskell98' to the build-depends in your .cabal file.It is a member of the hidden package `haskell2010-1.1.1.0'.Perhaps you need to add `haskell2010' to the build-depends in your .cabal file.Use -v to see a list of the files searched for.

Deleting the .cabal fixes it, but how can we make it work anyway (or at least give a good error message)?

In the comment, you wrote Causes error, catched in the upper function (I forgot to delete that). In which upper function did you mean?

@kazu-yamamoto kazu-yamamoto merged commit b574022 into kazu-yamamoto:master

1 check passed

Details default The Travis build passed
@kazu-yamamoto

Thank you for your contributions. I have mereged your patch.

Let's move to #118.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 3, 2013
  1. @nh2

    Don't reimplement listToMaybe

    nh2 authored
  2. @nh2
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 5 deletions.
  1. +3 −5 CabalApi.hs
View
8 CabalApi.hs
@@ -12,7 +12,7 @@ module CabalApi (
import Control.Applicative
import Control.Exception (throwIO)
import Data.List (intercalate)
-import Data.Maybe (fromJust, maybeToList)
+import Data.Maybe (maybeToList, listToMaybe)
import Data.Set (fromList, toList)
import Distribution.Package (Dependency(Dependency), PackageName(PackageName))
import Distribution.PackageDescription
@@ -71,12 +71,10 @@ getGHCOptions ghcOptions binfo = ghcOptions ++ exts ++ [lang] ++ libs ++ libDirs
-- Causes error, catched in the upper function.
cabalBuildInfo :: GenericPackageDescription -> BuildInfo
-cabalBuildInfo pd = fromJust $ fromLibrary pd <|> fromExecutable pd
+cabalBuildInfo pd = maybe emptyBuildInfo id $ fromLibrary pd <|> fromExecutable pd
where
fromLibrary c = libBuildInfo . condTreeData <$> condLibrary c
- fromExecutable c = buildInfo . condTreeData . snd <$> toMaybe (condExecutables c)
- toMaybe [] = Nothing
- toMaybe (x:_) = Just x
+ fromExecutable c = buildInfo . condTreeData . snd <$> listToMaybe (condExecutables c)
----------------------------------------------------------------
Something went wrong with that request. Please try again.