Skip to content

Commit

Permalink
tweaks to various error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Zheoni committed Aug 12, 2024
1 parent 951d7cb commit 32dd7ae
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
31 changes: 15 additions & 16 deletions src/analysis/event_consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ impl<'i, 'c> RecipeCollector<'i, 'c> {
let invalid_value = |possible| {
error!(
format!("Invalid value for config key '{key_t}': {value_t}"),
label!(value.span(), "this value is not supported")
label!(value.span(), "this value")
)
.label(label!(key.span(), "by this key"))
.label(label!(key.span(), "this key does not support"))
.hint(format!("Possible values are: {possible:?}"))
};

Expand Down Expand Up @@ -309,7 +309,7 @@ impl<'i, 'c> RecipeCollector<'i, 'c> {
),
label!(value.span(), "this value"),
)
.label(label!(key.span(), "is not supported by this key"))
.label(label!(key.span(), "this key does not support"))
.hint("It will be a regular metadata entry")
.set_source(err),
);
Expand Down Expand Up @@ -534,12 +534,14 @@ impl<'i, 'c> RecipeCollector<'i, 'c> {
.map(|l| l.span())
.unwrap_or(new_q_loc.span());

let (new_label, old_label) = match &e {
let (main_label, support_label) = match &e {
crate::quantity::IncompatibleUnits::MissingUnit { found } => {
let m = "this is missing a unit";
let f = "matching this one";
let m = "value missing unit";
let f = "found unit";
match found {
// new is mising
either::Either::Left(_) => (label!(new, m), label!(old, f)),
// old is missing
either::Either::Right(_) => (label!(new, f), label!(old, m)),
}
}
Expand All @@ -550,16 +552,16 @@ impl<'i, 'c> RecipeCollector<'i, 'c> {
(label!(new, b_q.to_string()), label!(old, a_q.to_string()))
}
crate::quantity::IncompatibleUnits::UnknownDifferentUnits { .. } => {
(label!(new, "this unit"), label!(old, "differs from this"))
(label!(new), label!(old))
}
};

self.ctx.warn(
warning!(
"Incompatible units prevent calculating total amount",
new_label
main_label
)
.label(old_label)
.label(support_label)
.set_source(e),
)
}
Expand Down Expand Up @@ -1283,11 +1285,11 @@ fn conflicting_reference_quantity_error(
) -> SourceDiag {
let mut e = error!(
"Conflicting component reference quantities",
label!(ref_quantity_span, "reference with quantity here")
label!(ref_quantity_span, "reference with quantity")
)
.label(label!(
def_span,
"definition with quantity outside a step here"
"definition with quantity outside a step"
))
.hint("If the component is not defined in a step and has a quantity, its references cannot have a quantity");
if implicit {
Expand All @@ -1303,12 +1305,9 @@ fn text_val_in_ref_warn(
) -> SourceDiag {
let mut w = warning!(
"Text value may prevent calculating total amount",
label!(text_quantity_span, "this text")
label!(text_quantity_span, "can't operate with text value")
)
.label(label!(
number_quantity_span,
"cannot be added to this value"
))
.label(label!(number_quantity_span, "numeric value"))
.hint("Use numeric values so they can be added together");
if implicit {
w.add_hint(IMPLICIT_REF_WARN);
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ fn write_report<'a>(
};
match err.severity() {
Severity::Error => writeln!(w, "{} {err}", "Error:".paint(sev_color))?,
Severity::Warning => writeln!(w, "{} {err}", "Warning: ".paint(sev_color))?,
Severity::Warning => writeln!(w, "{} {err}", "Warning:".paint(sev_color))?,
}
if let Some(source) = err.source() {
writeln!(w, " {} {source}", "╰▶ ".paint(sev_color))?;
Expand Down
5 changes: 2 additions & 3 deletions src/parser/quantity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ fn parse_regular_quantity<'i>(bp: &mut BlockParser<'_, 'i>) -> ParsedQuantity<'i
bp.warn(
warning!(
"Empty quantity unit",
label!(unit_text.span(), "add unit here")
label!(unit_separator.unwrap(), "remove this")
)
.label(label!(unit_separator.unwrap(), "or remove this"))
.hint("It will be as if the quantity has no unit"),
.hint("Add a unit or remove the separator"),
);
unit = None;
}
Expand Down
6 changes: 3 additions & 3 deletions src/parser/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,16 @@ fn parse_alias<'i>(
format!("Invalid {container}: multiple aliases"),
label!(bad_bit, "more than one alias defined here"),
)
.hint("A component can only have one alias. Remove the extra '|'"),
.hint("A component can only have one alias"),
);
None
} else if alias_text.is_text_empty() {
bp.error(
error!(
format!("Invalid {container}: empty alias"),
label!(alias_text.span(), "add alias here"),
label!(alias_sep.span, "remove this"),
)
.label(label!(alias_sep.span, "or remove this")),
.hint("Either remove the `|` or add an alias"),
);
None
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/quantity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ pub enum QuantityAddError {
pub enum IncompatibleUnits {
#[error("Missing unit: one unit is '{found}' but the other quantity is missing an unit")]
MissingUnit {
/// `Left`: Missing on the left hand side quantity
/// `Right`: Missing on the right hand side quantity
found: either::Either<QuantityUnit, QuantityUnit>,
},
#[error("Different physical quantity: '{a}' '{b}'")]
Expand Down

0 comments on commit 32dd7ae

Please sign in to comment.