mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 16:26:18 +02:00
fix error calls
This commit is contained in:
parent
f5d3215c87
commit
a3030e3c31
2 changed files with 11 additions and 21 deletions
|
@ -37,8 +37,7 @@ static void writeChannels()
|
||||||
{
|
{
|
||||||
auto channelsFD = AutoCloseFD{open(channelsList.c_str(), O_WRONLY | O_CLOEXEC | O_CREAT | O_TRUNC, 0644)};
|
auto channelsFD = AutoCloseFD{open(channelsList.c_str(), O_WRONLY | O_CLOEXEC | O_CREAT | O_TRUNC, 0644)};
|
||||||
if (!channelsFD)
|
if (!channelsFD)
|
||||||
throw Error("");
|
throw SysError("opening '%1%' for writing", channelsList);
|
||||||
// throw SysError("opening '%1%' for writing", channelsList);
|
|
||||||
for (const auto & channel : channels)
|
for (const auto & channel : channels)
|
||||||
writeFull(channelsFD.get(), channel.second + " " + channel.first + "\n");
|
writeFull(channelsFD.get(), channel.second + " " + channel.first + "\n");
|
||||||
}
|
}
|
||||||
|
@ -47,11 +46,9 @@ static void writeChannels()
|
||||||
static void addChannel(const string & url, const string & name)
|
static void addChannel(const string & url, const string & name)
|
||||||
{
|
{
|
||||||
if (!regex_search(url, std::regex("^(file|http|https)://")))
|
if (!regex_search(url, std::regex("^(file|http|https)://")))
|
||||||
throw Error("");
|
throw Error("invalid channel URL '%1%'", url);
|
||||||
// throw Error("invalid channel URL '%1%'", url);
|
|
||||||
if (!regex_search(name, std::regex("^[a-zA-Z0-9_][a-zA-Z0-9_\\.-]*$")))
|
if (!regex_search(name, std::regex("^[a-zA-Z0-9_][a-zA-Z0-9_\\.-]*$")))
|
||||||
throw Error("");
|
throw Error("invalid channel identifier '%1%'", name);
|
||||||
// throw Error("invalid channel identifier '%1%'", name);
|
|
||||||
readChannels();
|
readChannels();
|
||||||
channels[name] = url;
|
channels[name] = url;
|
||||||
writeChannels();
|
writeChannels();
|
||||||
|
@ -143,11 +140,9 @@ static void update(const StringSet & channelNames)
|
||||||
if (S_ISLNK(st.st_mode))
|
if (S_ISLNK(st.st_mode))
|
||||||
// old-skool ~/.nix-defexpr
|
// old-skool ~/.nix-defexpr
|
||||||
if (unlink(nixDefExpr.c_str()) == -1)
|
if (unlink(nixDefExpr.c_str()) == -1)
|
||||||
throw Error("");
|
throw SysError("unlinking %1%", nixDefExpr);
|
||||||
// throw SysError("unlinking %1%", nixDefExpr);
|
|
||||||
} else if (errno != ENOENT) {
|
} else if (errno != ENOENT) {
|
||||||
throw Error("");
|
throw SysError("getting status of %1%", nixDefExpr);
|
||||||
// throw SysError("getting status of %1%", nixDefExpr);
|
|
||||||
}
|
}
|
||||||
createDirs(nixDefExpr);
|
createDirs(nixDefExpr);
|
||||||
auto channelLink = nixDefExpr + "/channels";
|
auto channelLink = nixDefExpr + "/channels";
|
||||||
|
@ -199,12 +194,10 @@ static int _main(int argc, char ** argv)
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case cNone:
|
case cNone:
|
||||||
throw Error("");
|
throw UsageError("no command specified");
|
||||||
// throw UsageError("no command specified");
|
|
||||||
case cAdd:
|
case cAdd:
|
||||||
if (args.size() < 1 || args.size() > 2)
|
if (args.size() < 1 || args.size() > 2)
|
||||||
throw Error("");
|
throw UsageError("'--add' requires one or two arguments");
|
||||||
// throw UsageError("'--add' requires one or two arguments");
|
|
||||||
{
|
{
|
||||||
auto url = args[0];
|
auto url = args[0];
|
||||||
std::string name;
|
std::string name;
|
||||||
|
@ -220,14 +213,12 @@ static int _main(int argc, char ** argv)
|
||||||
break;
|
break;
|
||||||
case cRemove:
|
case cRemove:
|
||||||
if (args.size() != 1)
|
if (args.size() != 1)
|
||||||
throw Error("");
|
throw UsageError("'--remove' requires one argument");
|
||||||
// throw UsageError("'--remove' requires one argument");
|
|
||||||
removeChannel(args[0]);
|
removeChannel(args[0]);
|
||||||
break;
|
break;
|
||||||
case cList:
|
case cList:
|
||||||
if (!args.empty())
|
if (!args.empty())
|
||||||
throw Error("");
|
throw UsageError("'--list' expects no arguments");
|
||||||
// throw UsageError("'--list' expects no arguments");
|
|
||||||
readChannels();
|
readChannels();
|
||||||
for (const auto & channel : channels)
|
for (const auto & channel : channels)
|
||||||
std::cout << channel.first << ' ' << channel.second << '\n';
|
std::cout << channel.first << ' ' << channel.second << '\n';
|
||||||
|
@ -237,8 +228,7 @@ static int _main(int argc, char ** argv)
|
||||||
break;
|
break;
|
||||||
case cRollback:
|
case cRollback:
|
||||||
if (args.size() > 1)
|
if (args.size() > 1)
|
||||||
throw Error("");
|
throw UsageError("'--rollback' has at most one argument");
|
||||||
// throw UsageError("'--rollback' has at most one argument");
|
|
||||||
Strings envArgs{"--profile", profile};
|
Strings envArgs{"--profile", profile};
|
||||||
if (args.size() == 1) {
|
if (args.size() == 1) {
|
||||||
envArgs.push_back("--switch-generation");
|
envArgs.push_back("--switch-generation");
|
||||||
|
|
|
@ -906,7 +906,7 @@ static void opServe(Strings opFlags, Strings opArgs)
|
||||||
|
|
||||||
if (!writeAllowed) throw Error("building paths is not allowed");
|
if (!writeAllowed) throw Error("building paths is not allowed");
|
||||||
|
|
||||||
auto drvPath = store->parseStorePath(readString(in)); // inonal ony
|
auto drvPath = store->parseStorePath(readString(in)); // informational only
|
||||||
BasicDerivation drv;
|
BasicDerivation drv;
|
||||||
readDerivation(in, *store, drv);
|
readDerivation(in, *store, drv);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue