1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-23 17:31:08 +01:00

libflake-c: improve input override error message clarity

Make the C API error message more explicit about what went wrong and
why it's invalid. The new message explains that a zero-length path was
passed and clarifies that it would refer to the flake itself.

Updates the unit test to match the new error message.
This commit is contained in:
Robert Hensing 2025-12-20 02:10:37 +01:00
parent b1a230de75
commit cc88e1aa82
2 changed files with 3 additions and 2 deletions

View file

@ -164,7 +164,8 @@ nix_err nix_flake_lock_flags_add_input_override(
try {
auto path = nix::flake::NonEmptyInputAttrPath::parse(inputPath);
if (!path)
throw nix::UsageError("input override path cannot be empty");
throw nix::UsageError(
"input override path cannot be zero-length; it would refer to the flake itself, not an input");
flags->lockFlags->inputOverrides.emplace(std::move(*path), *flakeRef->flakeRef);
if (flags->lockFlags->writeLockFile) {
return nix_flake_lock_flags_set_mode_virtual(context, flags);

View file

@ -434,7 +434,7 @@ TEST_F(nix_api_store_test, nix_api_flake_lock_flags_add_input_override_empty_pat
// Verify error message contains expected text
const char * errMsg = nix_err_msg(nullptr, ctx, nullptr);
ASSERT_NE(nullptr, errMsg);
ASSERT_NE(std::string(errMsg).find("input override path cannot be empty"), std::string::npos);
ASSERT_NE(std::string(errMsg).find("input override path cannot be zero-length"), std::string::npos);
nix_flake_reference_free(flakeReference);
nix_flake_reference_parse_flags_free(parseFlags);