Skip to content

Commit dbf1095

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

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/libstore/derivations.cc

Lines changed: 8 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,11 @@ 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("Unsupported derivation JSON format version %d, only format version %d is currently supported.", version, expectedJsonVersionDerivation);
1455+
}
14511456

14521457
try {
14531458
auto outputs = getObject(valueAt(json, "outputs"));

0 commit comments

Comments
 (0)