]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/JSONSchema.pm
cleanup: newlines in die/warn
[pve-common.git] / src / PVE / JSONSchema.pm
index 95529258f19c24535e09dae21dc54471da8b1d37..f9b7a5adfa4da968523a473cda890123761dc43b 100644 (file)
@@ -137,7 +137,7 @@ register_format('pve-vmid', \&pve_verify_vmid);
 sub pve_verify_vmid {
     my ($vmid, $noerr) = @_;
 
-    if ($vmid !~ m/^[1-9][0-9]+$/) {
+    if ($vmid !~ m/^[1-9][0-9]{2,8}$/) {
        return undef if $noerr;
        die "value does not look like a valid VM ID\n";
     }
@@ -525,6 +525,7 @@ sub parse_property_string {
                    die "duplicate key in comma-separated list property: $default_key\n";
                }
            }
+           die "value without key, but schema does not define a default key\n" if !$default_key;
        } else {
            die "missing key in comma-separated list property\n";
        }
@@ -544,7 +545,7 @@ sub print_property_string {
 
     if (ref($format) ne 'HASH') {
        my $schema = $format_list->{$format};
-       die "not a valid format: $format" if !$schema;
+       die "not a valid format: $format\n" if !$schema;
        $format = $schema;
     }
 
@@ -567,7 +568,7 @@ sub print_property_string {
        # Skip default keys
        if ($format->{$key}->{default_key}) {
            if ($default_key) {
-               warn "multiple default keys in schema ($default_key, $key)";
+               warn "multiple default keys in schema ($default_key, $key)\n";
            } else {
                $default_key = $key;
                $skipped{$key} = 1;
@@ -587,7 +588,7 @@ sub print_property_string {
     foreach my $key (sort keys %$data) {
        delete $required{$key};
        next if $skipped{$key};
-       die "invalid key: $key" if !$allowed{$key};
+       die "invalid key: $key\n" if !$allowed{$key};
 
        my $typeformat = $format->{$key}->{format};
        my $value = $data->{$key};
@@ -597,12 +598,13 @@ sub print_property_string {
        if ($typeformat && $typeformat eq 'disk-size') {
            $text .= "$key=" . format_size($value);
        } else {
+           die "illegal value with commas for $key\n" if $value =~ /,/;
            $text .= "$key=$value";
        }
     }
 
     if (my $missing = join(',', keys %required)) {
-       die "missing properties: $missing";
+       die "missing properties: $missing\n";
     }
 
     return $text;