Cabal: "cabal new-build" fails when undefined flags are present with cryptic message

Created on 29 Apr 2017  路  6Comments  路  Source: haskell/cabal

I tried to build using cabal new-build and produced the following error:

Resolving dependencies...
Map.!: given key is not an element in the map
CallStack (from HasCallStack):
error, called at libraries/containers/Data/Map/Base.hs:489:16 in
containers-0.5.7.1:Data.Map.Base

It turned out that this was because I had

if flag(llvm-fast)
    ghc-options: -threaded -O3 -optlo-O3 -fllvm
else
    ghc-options: -threaded

in my .cabal file without a corresponding

Flag llvm-fast {
  Description: Enable build with llvm backend
  Default: False
}

If cabal could throw a nicer error, I'm sure it could save someone else a bit of time.

Thanks!

nix-local-build bug

All 6 comments

Agreed, we should definitely fail better here.

@23Skidoo fwiw, beyond this, I got a couple of additional warnings I wanted to implement for flags (like warning about defined but unused flags, wrong use of automatic flags which should rather be manual flags (coincidentally @vmchale's use-case is such one example), use of flags when they can better be expressed by other constructs, etc)

I'm all for better error messages but I can't reproduce this problem.

Given:

name: T4476
version: 1.0
build-type: Simple
cabal-version: >= 1.10

library
    build-depends: base
    if flag(llvm-fast)
        ghc-options: -O
    else
        ghc-options: -O2
    default-language: Haskell2010

when I new-build I get:

ezyang@sabre:~/Dev/cabal-shake/cabal-testsuite/PackageTests/NewBuild/T4476$ cabal new-build
These flags are used without having been defined: llvm-fast

on both e1cdb90f8eb0dd7bbf897a6a57aa4656d0c0b561 and 1.24. This error comes from the parser, where we perform a sanity check to make sure that only defined flags are used. @vmchale, is it possible that there was some other thing about your Cabal file that triggered? Can you paste the one that causes this problem?

a flag with a typo does it for me (definition + reference are different):

name:           HaXml
version:        1.25.6
--x-revision:     0
license:        LGPL
license-file:   COPYRIGHT
author:         Malcolm Wallace <[email protected]>
maintainer:     Malcolm Wallace <[email protected]>, Spiros Boosalis <[email protected]>
bug-reports:    http://github.com/sboosali/HaXml2/issues
copyright:      Malcolm Wallace 2017, 2018 Spiros Boosalis
homepage:       http://projects.haskell.org/HaXml/
category:       Text, XML
synopsis:       Utilities for manipulating XML documents
description:
        (Fork of @HaXml@. If you are the maintainer, please add a repository and issue-tracker).
        .
        Haskell utilities for parsing, filtering, transforming and
        generating XML documents.
build-type:     Simple
cabal-version:  >=1.8
extra-source-files:    LICENCE-GPL, LICENCE-LGPL, Makefile
tested-with:     GHC == 8.4.3

source-repository head
  type:     git
  location: git://github.com/sboosali/HaXml2.git

flag splitBase
  default: True
flag bytestringInBas
  default: False

library
  exposed-modules:
        Text.XML.HaXml,
        Text.XML.HaXml.ByteStringPP,
        Text.XML.HaXml.Combinators,
        Text.XML.HaXml.DtdToHaskell.Convert,
        Text.XML.HaXml.DtdToHaskell.Instance,
        Text.XML.HaXml.DtdToHaskell.TypeDef,
        Text.XML.HaXml.Escape,
        Text.XML.HaXml.Html.Generate,
        Text.XML.HaXml.Html.Parse,
        Text.XML.HaXml.Html.ParseLazy,
        Text.XML.HaXml.Html.Pretty,
        Text.XML.HaXml.Lex,
        Text.XML.HaXml.Namespaces,
        Text.XML.HaXml.OneOfN,
        Text.XML.HaXml.Parse,
        Text.XML.HaXml.ParseLazy,
        Text.XML.HaXml.Posn,
        Text.XML.HaXml.Pretty,
        Text.XML.HaXml.SAX,
        Text.XML.HaXml.Schema.Parse,
        Text.XML.HaXml.Schema.XSDTypeModel,
        Text.XML.HaXml.Schema.HaskellTypeModel,
        Text.XML.HaXml.Schema.NameConversion,
        Text.XML.HaXml.Schema.TypeConversion,
        Text.XML.HaXml.Schema.PrettyHaskell,
        Text.XML.HaXml.Schema.PrettyHsBoot,
        Text.XML.HaXml.Schema.PrimitiveTypes,
        Text.XML.HaXml.Schema.Environment,
        Text.XML.HaXml.ShowXmlLazy,
        Text.XML.HaXml.Types,
        Text.XML.HaXml.TypeMapping,
        Text.XML.HaXml.Util,
        Text.XML.HaXml.Validate,
        Text.XML.HaXml.Verbatim,
        Text.XML.HaXml.Version
        Text.XML.HaXml.Wrappers,
        Text.XML.HaXml.XmlContent,
        Text.XML.HaXml.XmlContent.Parser,
        Text.XML.HaXml.XmlContent.Haskell,
        Text.XML.HaXml.Xtract.Combinators,
        Text.XML.HaXml.Xtract.Lex,
        Text.XML.HaXml.Xtract.Parse
  if impl(ghc)
    exposed-modules:
        Text.XML.HaXml.Schema.Schema
  hs-source-dirs: src
  build-depends: polyparse >= 1.10, filepath
  if flag(splitBase)
    build-depends: base >= 3 && < 4.12, pretty, random, containers
  else
    build-depends: base < 3
  if flag(bytestringInBase)
    build-depends: base >= 2 && < 3
  else
    build-depends: base < 2 || >= 3, bytestring
  extensions: CPP, ExistentialQuantification
  nhc98-options: -K10M

Executable Canonicalise
  GHC-Options: -Wall
  Extensions:  CPP
  Hs-Source-Dirs: src/tools
  Main-Is: Canonicalise.hs
  build-depends: base, HaXml, pretty

Executable CanonicaliseLazy
  GHC-Options: -Wall
  Extensions:  CPP
  Hs-Source-Dirs: src/tools
  Main-Is: CanonicaliseLazy.hs
  build-depends: base, HaXml, pretty

Executable Xtract
  GHC-Options: -Wall
  Extensions:  CPP
  Hs-Source-Dirs: src/tools
  Main-Is: Xtract.hs
  build-depends: base, HaXml, pretty

Executable Validate
  GHC-Options: -Wall
  Extensions:  CPP
  Hs-Source-Dirs: src/tools
  Main-Is: Validate.hs
  build-depends: base, HaXml

Executable MkOneOf
  GHC-Options: -Wall
  Extensions:  CPP
  Hs-Source-Dirs: src/tools
  Main-Is: MkOneOf.hs
  build-depends: base, HaXml

Executable DtdToHaskell
  GHC-Options: -Wall
  Extensions:  CPP
  Hs-Source-Dirs: src/tools
  Main-Is: DtdToHaskell.hs
  build-depends: base, HaXml, pretty

Executable XsdToHaskell
  GHC-Options: -Wall
  Extensions:  CPP
  Hs-Source-Dirs: src/tools
  Main-Is: XsdToHaskell.hs
  build-depends: base, HaXml, pretty, polyparse, directory

Executable FpMLToHaskell
  GHC-Options: -Wall
  Extensions:  CPP
  Hs-Source-Dirs: src/tools
  Main-Is: FpMLToHaskell.hs
  build-depends: base, HaXml, pretty, polyparse, directory

I have replicated this on

cabal-install version 2.4.0.0
compiled using version 2.4.0.1 of the Cabal library

If I remove the flag definition or misspell the flag, then the error occurs:

-- Initial hpython-test-common.cabal generated by cabal init.  For further
-- documentation, see http://haskell.org/cabal/users-guide/

name:                hpython-test-common
version:             0.1.0.0
-- synopsis:
-- description:
license:             BSD3
license-file:        LICENSE
author:              Isaac Elliott
maintainer:          [email protected]
-- copyright:
category:            Testing
build-type:          Simple
extra-source-files:  CHANGELOG.md
cabal-version:       >=1.10

flag development
  default: False
  manual: True

library
  exposed-modules:     Helpers
  build-depends:       base >=4.11 && <5
  hs-source-dirs:      src
  ghc-options:         -Wall
                       -Wincomplete-patterns
                       -Wincomplete-record-updates
                       -Wunused-imports
                       -fno-warn-name-shadowing
  if flag(development)
    ghc-options:       -Werror
  default-language:    Haskell2010

I'm removing the tag, cause I can easily reproduce the unfriendly error myself

Was this page helpful?
0 / 5 - 0 ratings