From 9373a6089b9d01b85b31ea010aec168201589bad Mon Sep 17 00:00:00 2001 From: Michal Fox Date: Fri, 2 Oct 2026 16:42:14 +0200 Subject: [PATCH] fix #5607: schema: say what a valid configuration ID looks like The 'pve-configid' format is used for many IDs, for example the names of resource mappings, but an invalid ID only got rejected with: invalid configuration ID 'gpu@node1' which does not tell what is wrong with it, so users had to guess or look up the regex in the code. Explain the rules in the error message: an ID must start with a letter, be at least two characters long and only contain letters, digits, '-' and '_'. These are the same rules the tooltip of the 'ConfigId' validation in the web UI lists. Add a test for the message. Signed-off-by: Michal Fox --- src/PVE/JSONSchema.pm | 3 ++- test/format_test.pl | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 34f2949..0686b67 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -256,7 +256,8 @@ sub pve_verify_configid { if ($id !~ m/^$CONFIGID_RE\z/) { return undef if $noerr; - die "invalid configuration ID '$id'\n"; + die "invalid configuration ID '$id' - it must start with a letter, be at least two" + . " characters long and only contain letters, digits, '-' and '_'\n"; } return $id; } diff --git a/test/format_test.pl b/test/format_test.pl index 7b461ef..46256f4 100644 --- a/test/format_test.pl +++ b/test/format_test.pl @@ -25,6 +25,14 @@ foreach my $id (@$invalid_configids) { is(PVE::JSONSchema::pve_verify_configid($id, $noerr), undef, 'invalid configid'); } +eval { PVE::JSONSchema::pve_verify_configid('gpu@node1') }; +is( + $@, + "invalid configuration ID 'gpu\@node1' - it must start with a letter, be at least two" + . " characters long and only contain letters, digits, '-' and '_'\n", + 'invalid configid error explains the format', +); + # test some string rendering my $render_data = [ ["timestamp", 0, undef, "1970-01-01 01:00:00"],