From 99940358e34fdc4993a036163e23567b4d36386e Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 28 Sep 2021 10:11:56 +0200 Subject: [PATCH] ExtJsFormatter: use ParameterError to correctly compute 'errors' By default, 'errors' is now empty. Depend on proxmox 0.13.5. --- Cargo.toml | 2 +- pbs-api-types/Cargo.toml | 2 +- pbs-client/Cargo.toml | 2 +- pbs-config/Cargo.toml | 2 +- pbs-datastore/Cargo.toml | 2 +- pbs-fuse-loop/Cargo.toml | 2 +- pbs-tape/Cargo.toml | 2 +- pbs-tools/Cargo.toml | 2 +- proxmox-backup-client/Cargo.toml | 2 +- proxmox-file-restore/Cargo.toml | 2 +- proxmox-rest-server/Cargo.toml | 2 +- proxmox-rest-server/src/formatter.rs | 22 ++++++++++++++++++---- proxmox-restore-daemon/Cargo.toml | 2 +- proxmox-systemd/Cargo.toml | 2 +- pxar-bin/Cargo.toml | 2 +- 15 files changed, 32 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 88e8fbd1..76bde80d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,7 +94,7 @@ zstd = { version = "0.6", features = [ "bindgen" ] } pathpatterns = "0.1.2" pxar = { version = "0.10.1", features = [ "tokio-io" ] } -proxmox = { version = "0.13.4", features = [ "sortable-macro", "api-macro", "cli", "router", "tfa" ] } +proxmox = { version = "0.13.5", features = [ "sortable-macro", "api-macro", "cli", "router", "tfa" ] } proxmox-acme-rs = "0.2.1" proxmox-apt = "0.7.0" proxmox-http = { version = "0.4.0", features = [ "client", "http-helpers", "websocket" ] } diff --git a/pbs-api-types/Cargo.toml b/pbs-api-types/Cargo.toml index 878d6417..1ca768de 100644 --- a/pbs-api-types/Cargo.toml +++ b/pbs-api-types/Cargo.toml @@ -14,7 +14,7 @@ openssl = "0.10" regex = "1.2" serde = { version = "1.0", features = ["derive"] } -proxmox = { version = "0.13.4", default-features = false, features = [ "api-macro" ] } +proxmox = { version = "0.13.5", default-features = false, features = [ "api-macro" ] } proxmox-systemd = { path = "../proxmox-systemd" } pbs-tools = { path = "../pbs-tools" } diff --git a/pbs-client/Cargo.toml b/pbs-client/Cargo.toml index dc5d8928..83ef65a9 100644 --- a/pbs-client/Cargo.toml +++ b/pbs-client/Cargo.toml @@ -28,7 +28,7 @@ tower-service = "0.3.0" xdg = "2.2" pathpatterns = "0.1.2" -proxmox = { version = "0.13.4", default-features = false, features = [ "cli" ] } +proxmox = { version = "0.13.5", default-features = false, features = [ "cli" ] } proxmox-fuse = "0.1.1" proxmox-http = { version = "0.4.0", features = [ "client", "http-helpers", "websocket" ] } pxar = { version = "0.10.1", features = [ "tokio-io" ] } diff --git a/pbs-config/Cargo.toml b/pbs-config/Cargo.toml index 3249a8e9..7936686a 100644 --- a/pbs-config/Cargo.toml +++ b/pbs-config/Cargo.toml @@ -16,7 +16,7 @@ nix = "0.19.1" regex = "1.2" once_cell = "1.3.1" -proxmox = { version = "0.13.4", default-features = false, features = [ "cli" ] } +proxmox = { version = "0.13.5", default-features = false, features = [ "cli" ] } pbs-api-types = { path = "../pbs-api-types" } pbs-buildcfg = { path = "../pbs-buildcfg" } diff --git a/pbs-datastore/Cargo.toml b/pbs-datastore/Cargo.toml index 077ead47..45c0d276 100644 --- a/pbs-datastore/Cargo.toml +++ b/pbs-datastore/Cargo.toml @@ -25,7 +25,7 @@ zstd = { version = "0.6", features = [ "bindgen" ] } pathpatterns = "0.1.2" pxar = "0.10.1" -proxmox = { version = "0.13.4", default-features = false, features = [ "api-macro" ] } +proxmox = { version = "0.13.5", default-features = false, features = [ "api-macro" ] } pbs-api-types = { path = "../pbs-api-types" } pbs-tools = { path = "../pbs-tools" } diff --git a/pbs-fuse-loop/Cargo.toml b/pbs-fuse-loop/Cargo.toml index aa61d006..337ab9bd 100644 --- a/pbs-fuse-loop/Cargo.toml +++ b/pbs-fuse-loop/Cargo.toml @@ -14,7 +14,7 @@ nix = "0.19.1" regex = "1.2" tokio = { version = "1.6", features = [] } -proxmox = "0.13.4" +proxmox = "0.13.5" proxmox-fuse = "0.1.1" pbs-tools = { path = "../pbs-tools" } diff --git a/pbs-tape/Cargo.toml b/pbs-tape/Cargo.toml index 3dbeb17c..9224cee2 100644 --- a/pbs-tape/Cargo.toml +++ b/pbs-tape/Cargo.toml @@ -18,7 +18,7 @@ bitflags = "1.2.1" regex = "1.2" udev = ">= 0.3, <0.5" -proxmox = { version = "0.13.4", default-features = false, features = [] } +proxmox = { version = "0.13.5", default-features = false, features = [] } pbs-api-types = { path = "../pbs-api-types" } pbs-tools = { path = "../pbs-tools" } diff --git a/pbs-tools/Cargo.toml b/pbs-tools/Cargo.toml index d37ef865..7a33ab5e 100644 --- a/pbs-tools/Cargo.toml +++ b/pbs-tools/Cargo.toml @@ -31,7 +31,7 @@ url = "2.1" walkdir = "2" zstd = { version = "0.6", features = [ "bindgen" ] } -proxmox = { version = "0.13.4", default-features = false, features = [ "tokio" ] } +proxmox = { version = "0.13.5", default-features = false, features = [ "tokio" ] } pbs-buildcfg = { path = "../pbs-buildcfg" } pbs-runtime = { path = "../pbs-runtime" } diff --git a/proxmox-backup-client/Cargo.toml b/proxmox-backup-client/Cargo.toml index 42a4d09f..0b1d7f3b 100644 --- a/proxmox-backup-client/Cargo.toml +++ b/proxmox-backup-client/Cargo.toml @@ -22,7 +22,7 @@ zstd = { version = "0.6", features = [ "bindgen" ] } pathpatterns = "0.1.2" pxar = { version = "0.10.1", features = [ "tokio-io" ] } -proxmox = { version = "0.13.4", features = [ "sortable-macro", "api-macro", "cli", "router" ] } +proxmox = { version = "0.13.5", features = [ "sortable-macro", "api-macro", "cli", "router" ] } pbs-api-types = { path = "../pbs-api-types" } pbs-buildcfg = { path = "../pbs-buildcfg" } diff --git a/proxmox-file-restore/Cargo.toml b/proxmox-file-restore/Cargo.toml index 899fc984..382aa34f 100644 --- a/proxmox-file-restore/Cargo.toml +++ b/proxmox-file-restore/Cargo.toml @@ -16,7 +16,7 @@ tokio = { version = "1.6", features = [ "io-std", "rt", "rt-multi-thread", "time pxar = { version = "0.10.1", features = [ "tokio-io" ] } -proxmox = { version = "0.13.4", features = [ "api-macro", "cli" ] } +proxmox = { version = "0.13.5", features = [ "api-macro", "cli" ] } pbs-api-types = { path = "../pbs-api-types" } pbs-buildcfg = { path = "../pbs-buildcfg" } diff --git a/proxmox-rest-server/Cargo.toml b/proxmox-rest-server/Cargo.toml index afaf40e1..b0e53d19 100644 --- a/proxmox-rest-server/Cargo.toml +++ b/proxmox-rest-server/Cargo.toml @@ -25,7 +25,7 @@ tokio-openssl = "0.6.1" tower-service = "0.3.0" url = "2.1" -proxmox = { version = "0.13.4", features = [ "router"] } +proxmox = { version = "0.13.5", features = [ "router"] } # fixme: remove this dependency (pbs_tools::broadcast_future) pbs-tools = { path = "../pbs-tools" } diff --git a/proxmox-rest-server/src/formatter.rs b/proxmox-rest-server/src/formatter.rs index 7f41b382..601a7561 100644 --- a/proxmox-rest-server/src/formatter.rs +++ b/proxmox-rest-server/src/formatter.rs @@ -6,7 +6,7 @@ use serde_json::{json, Value}; use hyper::{Body, Response, StatusCode}; use hyper::header; -use proxmox::api::{HttpError, RpcEnvironment}; +use proxmox::api::{HttpError, schema::ParameterError, RpcEnvironment}; /// Extension to set error message for server side logging pub(crate) struct ErrorMessageExtension(pub String); @@ -61,6 +61,12 @@ struct JsonFormatter(); /// Format data as ``application/json`` /// +/// The returned json object contains the following properties: +/// +/// * ``data``: The result data (on success) +/// +/// Any result attributes set on ``rpcenv`` are also added to the object. +/// /// Errors generates a BAD_REQUEST containing the error /// message as string. pub static JSON_FORMATTER: &'static dyn OutputFormatter = &JsonFormatter(); @@ -136,10 +142,18 @@ impl OutputFormatter for ExtJsFormatter { fn format_error(&self, err: Error) -> Response { - let mut errors = vec![]; + let message: String; + let errors; - let message = err.to_string(); - errors.push(&message); + if let Some(param_err) = err.downcast_ref::() { + errors = param_err.errors().iter() + .map(|(name, err)| format!("parameter '{}': {}", name, err)) + .collect(); + message = String::from("parameter verification errors"); + } else { + errors = vec![]; + message = err.to_string(); + } let result = json!({ "message": message, diff --git a/proxmox-restore-daemon/Cargo.toml b/proxmox-restore-daemon/Cargo.toml index 871af5f9..3fbf552e 100644 --- a/proxmox-restore-daemon/Cargo.toml +++ b/proxmox-restore-daemon/Cargo.toml @@ -26,7 +26,7 @@ tokio-util = { version = "0.6", features = [ "codec", "io" ] } pathpatterns = "0.1.2" pxar = { version = "0.10.1", features = [ "tokio-io" ] } -proxmox = { version = "0.13.4", features = [ "router", "sortable-macro" ] } +proxmox = { version = "0.13.5", features = [ "router", "sortable-macro" ] } pbs-api-types = { path = "../pbs-api-types" } pbs-runtime = { path = "../pbs-runtime" } diff --git a/proxmox-systemd/Cargo.toml b/proxmox-systemd/Cargo.toml index 017a281c..ea715bf4 100644 --- a/proxmox-systemd/Cargo.toml +++ b/proxmox-systemd/Cargo.toml @@ -11,6 +11,6 @@ bitflags = "1.2.1" lazy_static = "1.4" nom = "5.1" -proxmox = { version = "0.13.4", default-features = false } +proxmox = { version = "0.13.5", default-features = false } #pbs-tools = { path = "../pbs-tools" } diff --git a/pxar-bin/Cargo.toml b/pxar-bin/Cargo.toml index 6121f7bc..036645d7 100644 --- a/pxar-bin/Cargo.toml +++ b/pxar-bin/Cargo.toml @@ -16,7 +16,7 @@ serde_json = "1.0" tokio = { version = "1.6", features = [ "rt", "rt-multi-thread" ] } pathpatterns = "0.1.2" -proxmox = { version = "0.13.4", default-features = false, features = [] } +proxmox = { version = "0.13.5", default-features = false, features = [] } pxar = { version = "0.10.1", features = [ "tokio-io" ] } pbs-client = { path = "../pbs-client" }