Skip to content

Commit 85fce01

Browse files
committed
Return reasons for build failures
1 parent b9771db commit 85fce01

11 files changed

Lines changed: 45 additions & 39 deletions

File tree

backends/src/anchor/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ impl RunHigh for Anchor {
133133
context: &LightContext,
134134
test_name: &str,
135135
span: &Span,
136-
) -> Result<Option<(Exec, Option<Box<Postprocess>>)>> {
136+
) -> Result<Result<(Exec, Option<Box<Postprocess>>)>> {
137137
if let Err(error) = self.check(context, &span.source_file) {
138-
debug!("{error}");
139-
return Ok(None);
138+
return Ok(Err(error));
140139
}
141140

142141
let backup = self.patch_anchor_toml(&span.source_file, false)?;

backends/src/hardhat/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ impl RunHigh for Hardhat {
7878
context: &LightContext,
7979
test_name: &str,
8080
span: &Span,
81-
) -> Result<Option<(Exec, Option<Box<Postprocess>>)>> {
81+
) -> Result<Result<(Exec, Option<Box<Postprocess>>)>> {
8282
if let Err(error) = compile(context) {
83-
debug!("{error}");
84-
return Ok(None);
83+
return Ok(Err(error));
8584
}
8685

8786
let mut command = ts::utils::script("npx");

backends/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<T: RunHigh> RunHigh for ParseAdapter<T> {
140140
context: &LightContext,
141141
test_name: &str,
142142
span: &Span,
143-
) -> Result<Option<(Exec, Option<Box<Postprocess>>)>> {
143+
) -> Result<Result<(Exec, Option<Box<Postprocess>>)>> {
144144
self.0.exec(context, test_name, span)
145145
}
146146
}

backends/src/running.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<T: RunLow> RunHigh for RunAdapter<T> {
154154
context: &LightContext,
155155
test_name: &str,
156156
span: &Span,
157-
) -> Result<Option<(Exec, Option<Box<Postprocess>>)>> {
157+
) -> Result<Result<(Exec, Option<Box<Postprocess>>)>> {
158158
{
159159
let mut command = self.0.command_to_build_test(context, test_name, span);
160160
command.args(&context.opts.args);
@@ -163,8 +163,7 @@ impl<T: RunLow> RunHigh for RunAdapter<T> {
163163

164164
let output = command.output_stripped_of_ansi_escapes()?;
165165
if !output.status().success() {
166-
debug!("{output}");
167-
return Ok(None);
166+
return Ok(Err(output.into()));
168167
}
169168
}
170169

@@ -185,7 +184,7 @@ impl<T: RunLow> RunHigh for RunAdapter<T> {
185184
let test_name = test_name.to_owned();
186185
let span = span.clone();
187186

188-
Ok(Some((
187+
Ok(Ok((
189188
exec,
190189
init_f_test.map(|(init, f)| -> Box<Postprocess> {
191190
Box::new(move |context: &LightContext, mut popen| {

backends/src/ts/inner/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl Inner {
131131
test_name: &str,
132132
span: &Span,
133133
command: &Command,
134-
) -> Result<Option<(Exec, Option<Box<Postprocess>>)>> {
134+
) -> Result<Result<(Exec, Option<Box<Postprocess>>)>> {
135135
let mut source_file_it_message_state_map =
136136
self.source_file_it_message_state_map.borrow_mut();
137137
#[allow(clippy::expect_used)]
@@ -144,20 +144,21 @@ impl Inner {
144144
.entry(test_name.to_owned())
145145
.or_default();
146146
if *state != ItMessageState::Found {
147+
let msg = format!("`it` message {test_name:?} was not found during dry run");
147148
if *state == ItMessageState::NotFound {
148149
source_warn(
149150
context,
150151
Warning::ItMessageNotFound,
151152
span,
152-
&format!("`it` message {test_name:?} was not found during dry run"),
153+
&msg,
153154
WarnFlags::empty(),
154155
)?;
155156
*state = ItMessageState::WarningEmitted;
156157
}
157-
// smoelius: Returning `None` here causes Necessist to associate `Outcome::Nonbuildable`
158-
// with this span. This is not ideal, but there is no ideal choice for this situation
159-
// currently.
160-
return Ok(None);
158+
// smoelius: Returning an error here causes Necessist to associate
159+
// `Outcome::Nonbuildable` with this span. This is not ideal, but there is no ideal
160+
// choice for this situation currently.
161+
return Ok(Err(anyhow!(msg)));
161162
}
162163

163164
let mut exec = util::exec_from_command(command);
@@ -166,7 +167,7 @@ impl Inner {
166167

167168
debug!("{exec:?}");
168169

169-
Ok(Some((exec, None)))
170+
Ok(Ok((exec, None)))
170171
}
171172
}
172173

backends/src/ts/mocha.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl MochaLike for Mocha {
6969
test_name: &str,
7070
span: &Span,
7171
command: &Command,
72-
) -> Result<Option<(Exec, Option<Box<Postprocess>>)>> {
72+
) -> Result<Result<(Exec, Option<Box<Postprocess>>)>> {
7373
self.0.exec(context, test_name, span, command)
7474
}
7575
}

backends/src/ts/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub trait MochaLike {
3636
test_name: &str,
3737
span: &Span,
3838
command: &Command,
39-
) -> Result<Option<(Exec, Option<Box<Postprocess>>)>>;
39+
) -> Result<Result<(Exec, Option<Box<Postprocess>>)>>;
4040
}
4141

4242
impl ParseLow for Box<dyn MochaLike> {

backends/src/ts/vitest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl MochaLike for Vitest {
9595
test_name: &str,
9696
span: &Span,
9797
command: &Command,
98-
) -> Result<Option<(Exec, Option<Box<Postprocess>>)>> {
98+
) -> Result<Result<(Exec, Option<Box<Postprocess>>)>> {
9999
self.0.exec(context, test_name, span, command)
100100
}
101101
}

backends/src/vitest/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl RunHigh for Vitest {
8484
context: &LightContext,
8585
test_name: &str,
8686
span: &Span,
87-
) -> Result<Option<(Exec, Option<Box<Postprocess>>)>> {
87+
) -> Result<Result<(Exec, Option<Box<Postprocess>>)>> {
8888
let command = command_to_run_test(context, &span.source_file);
8989

9090
self.mocha_adapter

core/src/core.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -368,21 +368,25 @@ fn run(mut context: Context, source_file_span_test_map: SourceFileSpanTestMap) -
368368
return Ok(outcome);
369369
}
370370

371-
if let Some((exec, postprocess)) =
372-
context.backend.exec(&context.light(), test_name, span)?
373-
{
374-
// smoelius: Even if the removal is explicit (i.e., not with
375-
// instrumentation), it doesn't hurt to set `NECESSIST_REMOVAL`.
376-
let exec = exec.env("NECESSIST_REMOVAL", span.id());
377-
378-
perform_exec(&context, exec, postprocess)
379-
} else {
380-
assert!(
381-
explicit_removal,
382-
"Instrumentation failed to build after it was verified to"
383-
);
384-
385-
Ok(Some(Outcome::Nonbuildable))
371+
let result = context.backend.exec(&context.light(), test_name, span)?;
372+
373+
match result {
374+
Ok((exec, postprocess)) => {
375+
// smoelius: Even if the removal is explicit (i.e., not with
376+
// instrumentation), it doesn't hurt to set `NECESSIST_REMOVAL`.
377+
let exec = exec.env("NECESSIST_REMOVAL", span.id());
378+
379+
perform_exec(&context, exec, postprocess)
380+
}
381+
Err(error) => {
382+
assert!(
383+
explicit_removal,
384+
"Instrumentation failed to build after it was verified to: \
385+
{error}"
386+
);
387+
388+
Ok(Some(Outcome::Nonbuildable))
389+
}
386390
}
387391
})?;
388392

0 commit comments

Comments
 (0)