#6133 closed bug (fixed)

bad error message when incorrect format package db is supplied

Reported by: gfxmonk Owned by: pcapriotti
Priority: normal Milestone:
Component: ghc-pkg Version: 7.0.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

I built a standalone package using cabal, and then ran:

cabal register --gen-pkg-config="$BUILDDIR/package.conf" --builddir="$BUILDDIR"

When I tried to compile or run a haskell file (using ghc or runghc), with GHC_PACKAGE_PATH="$BUILDDIR/package.conf", I get:

ghc: panic! (the 'impossible' happened)
  (GHC version 7.0.4 for x86_64-unknown-linux):
	Prelude.read: no parse

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Curiosity and exploration reveals (I think - I am largely guessing) that the thing that's supposed to be in GHC_PACKAGE_PATH is the haskell-syntax "package.conf.inplace", not "package.conf". This took me a while and a lot of frustration however, so a better error would be appreciated for next time I forget how this works.

I'm also not entirely sure where package.conf.inplace comes from, it seems to be a side process of the registration but I can't find any documentation or instructions on building one speicifically (rather than accidentally).

Change History (6)

comment:1 Changed 23 months ago by duncan

So yes, the real problem here is the poor error message.

When you use cabal register --gen-pkg-config= you make a package registration file. This is not a ghc package database, it is the input for an element of such a database. You insert the package registration info into an existing ghc package database using ghc-pkg register.

So what you really want to do is:

cabal register --gen-pkg-config="$BUILDDIR/foo.pkg" --builddir="$BUILDDIR"
ghc-pkg init $BUILDDIR/package.conf
ghc-pkg register --package-conf=$BUILDDIR/package.conf foo.pkg

ghc / ghci -package-conf $BUILDDIR/package.conf ...

The thing that is used with ghc -package-conf or equivalently with the GHC_PACKAGE_PATH var is a ghc-pkg database.

The format used by ghc-pkg register, ghc-pkg describe and cabal register is the human readable one, and is described by the Cabal spec. The ghc-pkg database format is a ghc specififc implementation detail and is not intended for people to look at.

If you're interested, the ghc-pkg databases come in two internal formats (though you never need to mess with their internal details). One is as a single file using Haskell read/show format. The other is as a directory containing one file per package plus a binary cache.

So the reason you get your error is that ghc looks at the file you've given, determines that it's not a directory but an old-style single file db, and tries to read it using read which fails because what you've actually got in the file is the package registration info in the format standardised by Cabal.

So ghc should be using reads rather than read and then it can emit a specific error message to say that the given file is not in the format created by ghc-pkg.

comment:2 follow-up: Changed 23 months ago by gfxmonk

Thanks very much for the details, that clears things up onsiderably. Is there a way to explicitly generate of an "old style" db file instead of a folder & cache? These packages will only ever have one library per-db, and will be readonly - so it seems like that would be a better fit. Sorry if that's a little off topic for the actual bug, we can move this to the mailing list if you'd prefer.

comment:3 in reply to: ↑ 2 Changed 23 months ago by duncan

  • Summary changed from ghc dies when I use a package.conf in $GHC_PACKAGE_PATH to bad error message when incorrect format package db is supplied

Replying to gfxmonk:

Is there a way to explicitly generate of an "old style" db file instead of a folder & cache?

Yes:

old style:

echo [] > package.conf

new style:

ghc-pkg init package.conf.d

comment:4 Changed 23 months ago by pcapriotti

  • Difficulty set to Unknown
  • Owner set to pcapriotti

comment:5 Changed 23 months ago by p.capriotti@…

commit 50fddb2b046605315f903d9b744780497cc978de

Author: Paolo Capriotti <p.capriotti@gmail.com>
Date:   Mon Jun 4 11:59:25 2012 +0100

    Improve error message for invalid package db file (#6133).
    
    Use `reads` instead of `read` to parse package configuration files, and
    report a meaningful error when the parsing fails.

 compiler/main/Packages.lhs |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

comment:6 Changed 23 months ago by pcapriotti

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.