|
1 | 1 | use crate::snippet::Style; |
2 | 2 | use crate::{DiagnosticArg, DiagnosticMessage, FluentBundle}; |
3 | 3 | use rustc_data_structures::sync::Lrc; |
4 | | -use rustc_error_messages::FluentArgs; |
| 4 | +use rustc_error_messages::{ |
| 5 | + fluent_bundle::resolver::errors::{ReferenceKind, ResolverError}, |
| 6 | + FluentArgs, FluentError, |
| 7 | +}; |
5 | 8 | use std::borrow::Cow; |
6 | 9 |
|
7 | 10 | /// Convert diagnostic arguments (a rustc internal type that exists to implement |
@@ -102,14 +105,31 @@ pub trait Translate { |
102 | 105 | .or_else(|| translate_with_bundle(self.fallback_fluent_bundle())) |
103 | 106 | .map(|(translated, errs)| { |
104 | 107 | // Always bail out for errors with the fallback bundle. |
105 | | - assert!( |
106 | | - errs.is_empty(), |
107 | | - "identifier: {:?}, attr: {:?}, args: {:?}, errors: {:?}", |
108 | | - identifier, |
109 | | - attr, |
110 | | - args, |
111 | | - errs |
112 | | - ); |
| 108 | + |
| 109 | + let mut help_messages = vec![]; |
| 110 | + |
| 111 | + if !errs.is_empty() { |
| 112 | + for error in &errs { |
| 113 | + match error { |
| 114 | + FluentError::ResolverError(ResolverError::Reference( |
| 115 | + ReferenceKind::Message { id, .. }, |
| 116 | + )) if args.iter().any(|(arg_id, _)| arg_id == id) => { |
| 117 | + help_messages.push(format!("Argument `{id}` exists but was not referenced correctly. Try using `{{${id}}}` instead")); |
| 118 | + } |
| 119 | + _ => {} |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + panic!( |
| 124 | + "Encountered errors while formatting message for `{identifier}`\n\ |
| 125 | + help: {}\n\ |
| 126 | + attr: `{attr:?}`\n\ |
| 127 | + args: `{args:?}`\n\ |
| 128 | + errors: `{errs:?}`", |
| 129 | + help_messages.join("\nhelp: ") |
| 130 | + ); |
| 131 | + } |
| 132 | + |
113 | 133 | translated |
114 | 134 | }) |
115 | 135 | .expect("failed to find message in primary or fallback fluent bundles") |
|
0 commit comments