MCPcopy Create free account
hub / github.com/PRQL/prql / compose_display

Method compose_display

prqlc/prqlc/src/error_message.rs:166–198  ·  view source on GitHub ↗
(&self, source_path: PathBuf, cache: &mut FileTreeCache)

Source from the content-addressed store, hash-verified

164
165impl ErrorMessage {
166 fn compose_display(&self, source_path: PathBuf, cache: &mut FileTreeCache) -> Option<String> {
167 // We always pass color to ariadne as true, and then (currently) strip later.
168 let config = Config::default().with_color(true);
169
170 // Create a span tuple with the source path and the error range
171 let span = Range::from(self.span?);
172 let error_span = (source_path.clone(), span.start..span.end);
173
174 let mut report = Report::build(ReportKind::Error, error_span.clone())
175 .with_config(config)
176 .with_label(Label::new(error_span).with_message(&self.reason));
177
178 if let Some(code) = &self.code {
179 report = report.with_code(code);
180 }
181
182 // I don't know how to set multiple hints...
183 if !self.hints.is_empty() {
184 report.set_help(&self.hints[0]);
185 }
186 if self.hints.len() > 1 {
187 report.set_note(&self.hints[1]);
188 }
189 if self.hints.len() > 2 {
190 report.set_message(&self.hints[2]);
191 }
192
193 let mut out = Vec::new();
194 report.finish().write(cache, &mut out).ok()?;
195 String::from_utf8(out)
196 .ok()
197 .map(|x| crate::utils::maybe_strip_colors(x.as_str()))
198 }
199
200 fn compose_location(&self, source: &Source) -> Option<SourceLocation> {
201 let span = self.span?;

Callers 1

composedMethod · 0.80

Calls 8

maybe_strip_colorsFunction · 0.85
with_colorMethod · 0.80
with_codeMethod · 0.80
is_emptyMethod · 0.80
lenMethod · 0.80
mapMethod · 0.80
as_strMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected