Skip to content

Commit

Permalink
builtins.fetchMercurial: improve error message when hg is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
LnL7 committed Oct 30, 2018
1 parent b03df7a commit 218ef8b
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/libexpr/primops/fetchMercurial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,30 @@ static void prim_fetchMercurial(EvalState & state, const Pos & pos, Value * * ar
// whitelist. Ah well.
state.checkURI(url);

auto hgInfo = exportMercurial(state.store, url, rev, name);

state.mkAttrs(v, 8);
mkString(*state.allocAttr(v, state.sOutPath), hgInfo.storePath, PathSet({hgInfo.storePath}));
mkString(*state.allocAttr(v, state.symbols.create("branch")), hgInfo.branch);
mkString(*state.allocAttr(v, state.symbols.create("rev")), hgInfo.rev);
mkString(*state.allocAttr(v, state.symbols.create("shortRev")), std::string(hgInfo.rev, 0, 12));
mkInt(*state.allocAttr(v, state.symbols.create("revCount")), hgInfo.revCount);
v.attrs->sort();

if (state.allowedPaths)
state.allowedPaths->insert(hgInfo.storePath);
try {
auto hgInfo = exportMercurial(state.store, url, rev, name);

state.mkAttrs(v, 8);
mkString(*state.allocAttr(v, state.sOutPath), hgInfo.storePath, PathSet({hgInfo.storePath}));
mkString(*state.allocAttr(v, state.symbols.create("branch")), hgInfo.branch);
mkString(*state.allocAttr(v, state.symbols.create("rev")), hgInfo.rev);
mkString(*state.allocAttr(v, state.symbols.create("shortRev")), std::string(hgInfo.rev, 0, 12));
mkInt(*state.allocAttr(v, state.symbols.create("revCount")), hgInfo.revCount);
v.attrs->sort();

if (state.allowedPaths)
state.allowedPaths->insert(hgInfo.storePath);
} catch (ExecError & e) {
if (e.status / 256 == 127) {
std::ostringstream out;
out << e.what() << std::endl;
out << "The program 'hg' is currently not installed. It is required by builtins.fetchMercurial" << std::endl;
out << "You can install it by typing one of the following:" << std::endl;
out << "nix-env -f '<nixpkgs>' -iA mercurial";
throw ExecError(e.status, out.str());
}
throw;
}
}

static RegisterPrimOp r("fetchMercurial", 1, prim_fetchMercurial);
Expand Down

0 comments on commit 218ef8b

Please sign in to comment.