Skip to content

Commit a2e432d

Browse files
committed
provisioning: Report expected error for invalid type
Signed-off-by: Ikey Doherty <[email protected]>
1 parent 7b16f86 commit a2e432d

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

crates/provisioning/src/commands/find_disk.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ pub(crate) fn parse(context: Context<'_>) -> Result<super::Command, crate::Error
2424
0 => {
2525
return Err(crate::InvalidArguments {
2626
at: context.node.span(),
27-
advice: Some("find-disk <name> - provide a name for the storage device".into()),
27+
advice: Some("find-disk <name> - you must provide a name to store the object".into()),
2828
}
2929
.into())
3030
}
3131
1 => arguments[0].value().as_string().ok_or(crate::InvalidType {
3232
at: arguments[0].span(),
33+
expected_type: crate::KdlType::String,
3334
})?,
3435
_ => {
3536
return Err(crate::InvalidArguments {

crates/provisioning/src/errors.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::{io, sync::Arc};
77
use miette::{Diagnostic, NamedSource, SourceSpan};
88
use thiserror::Error;
99

10+
use crate::KdlType;
11+
1012
/// Error type for the provisioning crate
1113
#[derive(Diagnostic, Debug, Error)]
1214
pub enum Error {
@@ -58,11 +60,14 @@ pub struct ParseError {
5860

5961
/// Error for invalid types
6062
#[derive(Debug, Diagnostic, Error)]
61-
#[error("invalid type")]
63+
#[error("invalid type, expected {expected_type}")]
6264
#[diagnostic(severity(error))]
6365
pub struct InvalidType {
6466
#[label]
6567
pub at: SourceSpan,
68+
69+
/// The expected type
70+
pub expected_type: KdlType,
6671
}
6772

6873
/// Error for missing mandatory properties

crates/provisioning/src/helpers.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use kdl::{KdlEntry, KdlNode};
66

7-
use crate::{Error, InvalidType, MissingProperty};
7+
use crate::{Error, InvalidType, KdlType, MissingProperty};
88

99
// Get a property from a node
1010
pub(crate) fn get_kdl_property<'a>(node: &'a KdlNode, name: &'static str) -> Result<&'a KdlEntry, Error> {
@@ -19,7 +19,10 @@ pub(crate) fn get_kdl_property<'a>(node: &'a KdlNode, name: &'static str) -> Res
1919

2020
// Get a string property from a value
2121
pub(crate) fn kdl_value_to_string(entry: &kdl::KdlEntry) -> Result<String, Error> {
22-
let value = entry.value().as_string().ok_or(InvalidType { at: entry.span() })?;
22+
let value = entry.value().as_string().ok_or(InvalidType {
23+
at: entry.span(),
24+
expected_type: KdlType::String,
25+
})?;
2326

2427
Ok(value.to_owned())
2528
}

0 commit comments

Comments
 (0)