Skip to content

Commit 97a89bc

Browse files
committed
feat: add snapshot_output to IncrementalBuildError
1 parent 7ce8778 commit 97a89bc

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

rewatch/src/build.rs

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,40 @@ fn format_step(current: usize, total: usize) -> console::StyledObject<String> {
260260
}
261261

262262
#[derive(Debug, Clone)]
263-
pub enum IncrementalBuildError {
263+
pub enum IncrementalBuildErrorKind {
264264
SourceFileParseError,
265265
CompileError(Option<String>),
266266
}
267267

268+
#[derive(Debug, Clone)]
269+
pub struct IncrementalBuildError {
270+
pub snapshot_output: bool,
271+
pub kind: IncrementalBuildErrorKind,
272+
}
273+
268274
impl fmt::Display for IncrementalBuildError {
269275
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
270-
match self {
271-
Self::SourceFileParseError => write!(f, "{} {}Could not parse Source Files", LINE_CLEAR, CROSS,),
272-
Self::CompileError(Some(e)) => {
273-
write!(f, "{} {}Failed to Compile. Error: {e}", LINE_CLEAR, CROSS,)
276+
match &self.kind {
277+
IncrementalBuildErrorKind::SourceFileParseError => {
278+
if self.snapshot_output {
279+
write!(f, "{} Could not parse Source Files", LINE_CLEAR,)
280+
} else {
281+
write!(f, "{} {}Could not parse Source Files", LINE_CLEAR, CROSS,)
282+
}
283+
}
284+
IncrementalBuildErrorKind::CompileError(Some(e)) => {
285+
if self.snapshot_output {
286+
write!(f, "{} Failed to Compile. Error: {e}", LINE_CLEAR,)
287+
} else {
288+
write!(f, "{} {}Failed to Compile. Error: {e}", LINE_CLEAR, CROSS,)
289+
}
274290
}
275-
Self::CompileError(None) => {
276-
write!(f, "{} {}Failed to Compile. See Errors Above", LINE_CLEAR, CROSS,)
291+
IncrementalBuildErrorKind::CompileError(None) => {
292+
if self.snapshot_output {
293+
write!(f, "{} Failed to Compile. See Errors Above", LINE_CLEAR,)
294+
} else {
295+
write!(f, "{} {}Failed to Compile. See Errors Above", LINE_CLEAR, CROSS,)
296+
}
277297
}
278298
}
279299
}
@@ -344,7 +364,10 @@ pub fn incremental_build(
344364
}
345365

346366
println!("{}", &err);
347-
return Err(IncrementalBuildError::SourceFileParseError);
367+
return Err(IncrementalBuildError {
368+
kind: IncrementalBuildErrorKind::SourceFileParseError,
369+
snapshot_output,
370+
});
348371
}
349372
}
350373
let timing_deps = Instant::now();
@@ -397,7 +420,10 @@ pub fn incremental_build(
397420
|size| pb.set_length(size),
398421
build_dev_deps,
399422
)
400-
.map_err(|e| IncrementalBuildError::CompileError(Some(e.to_string())))?;
423+
.map_err(|e| IncrementalBuildError {
424+
kind: IncrementalBuildErrorKind::CompileError(Some(e.to_string())),
425+
snapshot_output,
426+
})?;
401427

402428
let compile_duration = start_compiling.elapsed();
403429

@@ -427,7 +453,10 @@ pub fn incremental_build(
427453
if helpers::contains_ascii_characters(&compile_errors) {
428454
println!("{}", &compile_errors);
429455
}
430-
Err(IncrementalBuildError::CompileError(None))
456+
Err(IncrementalBuildError {
457+
kind: IncrementalBuildErrorKind::CompileError(None),
458+
snapshot_output,
459+
})
431460
} else {
432461
if show_progress {
433462
if snapshot_output {

0 commit comments

Comments
 (0)