Skip to content

Commit 80b1d7b

Browse files
committed
Better version error for JSON derivation decoding
It now says which (other) version was encountered instead
1 parent 5b15544 commit 80b1d7b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/libstore/derivations.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,13 +1381,15 @@ adl_serializer<DerivationOutput>::from_json(const json & _json, const Experiment
13811381
}
13821382
}
13831383

1384+
static unsigned constexpr expectedJsonVersionDerivation = 4;
1385+
13841386
void adl_serializer<Derivation>::to_json(json & res, const Derivation & d)
13851387
{
13861388
res = nlohmann::json::object();
13871389

13881390
res["name"] = d.name;
13891391

1390-
res["version"] = 4;
1392+
res["version"] = expectedJsonVersionDerivation;
13911393

13921394
{
13931395
nlohmann::json & outputsObj = res["outputs"];
@@ -1446,8 +1448,14 @@ Derivation adl_serializer<Derivation>::from_json(const json & _json, const Exper
14461448

14471449
res.name = getString(valueAt(json, "name"));
14481450

1449-
if (valueAt(json, "version") != 4)
1450-
throw Error("Only derivation format version 4 is currently supported.");
1451+
{
1452+
auto version = getUnsigned(valueAt(json, "version"));
1453+
if (valueAt(json, "version") != expectedJsonVersionDerivation)
1454+
throw Error(
1455+
"Unsupported derivation JSON format version %d, only format version %d is currently supported.",
1456+
version,
1457+
expectedJsonVersionDerivation);
1458+
}
14511459

14521460
try {
14531461
auto outputs = getObject(valueAt(json, "outputs"));

0 commit comments

Comments
 (0)