Skip to content

Commit 508e87f

Browse files
committed
chore(core): fix failing unit test (#23392)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> ## Current Behavior <!-- This is the behavior we have today --> Getting inputs sometimes may cause Nx to panic ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Getting inputs will return an error rather than panic which should come along with stack traces. Also, a test which sometimes.. triggered the panic... is maybe fixed? ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # (cherry picked from commit 09fd1bb)
1 parent 2cae242 commit 508e87f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

packages/nx/src/native/tasks/inputs.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,21 @@ pub(super) fn get_inputs<'a>(
1919
let project_node = project_graph
2020
.nodes
2121
.get(&task.target.project)
22-
.expect("Task target should always have a project");
23-
let named_inputs = get_named_inputs(nx_json, project_node);
22+
.ok_or(anyhow::format_err!(
23+
"Project {} not found in the project graph",
24+
task.target.project
25+
))?;
26+
2427
let target_data = project_node
2528
.targets
2629
.get(&task.target.target)
27-
.expect("Task target should always have a target");
30+
.ok_or(anyhow::format_err!(
31+
"Project \"{}\" does not have a target \"{}\"",
32+
task.target.project,
33+
task.target.target
34+
))?;
2835

36+
let named_inputs = get_named_inputs(nx_json, project_node);
2937
let inputs: Option<Vec<Input>> = target_data
3038
.inputs
3139
.as_ref()

packages/nx/src/native/tests/planner.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TempFs } from '../../internal-testing-utils/temp-fs';
2+
23
let tempFs = new TempFs('task-planner');
34

45
import { HashPlanner, transferProjectGraph } from '../index';
@@ -164,10 +165,10 @@ describe('task planner', () => {
164165
{}
165166
);
166167

167-
const planner = new HashPlanner(
168-
nxJson as any,
169-
transferProjectGraph(transformProjectGraphForRust(projectGraph))
168+
const ref = transferProjectGraph(
169+
transformProjectGraphForRust(projectGraph)
170170
);
171+
const planner = new HashPlanner(nxJson as any, ref);
171172

172173
await assertHashPlan(
173174
taskGraph.tasks['parent:build'],

0 commit comments

Comments
 (0)