Skip to content

Commit

Permalink
chore(core): fix failing unit test (#23392)
Browse files Browse the repository at this point in the history
<!-- 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 #
  • Loading branch information
FrozenPandaz committed May 14, 2024
1 parent cfadd7d commit 09fd1bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 11 additions & 3 deletions packages/nx/src/native/tasks/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ pub(super) fn get_inputs<'a>(
let project_node = project_graph
.nodes
.get(&task.target.project)
.expect("Task target should always have a project");
let named_inputs = get_named_inputs(nx_json, project_node);
.ok_or(anyhow::format_err!(
"Project {} not found in the project graph",
task.target.project
))?;

let target_data = project_node
.targets
.get(&task.target.target)
.expect("Task target should always have a target");
.ok_or(anyhow::format_err!(
"Project \"{}\" does not have a target \"{}\"",
task.target.project,
task.target.target
))?;

let named_inputs = get_named_inputs(nx_json, project_node);
let inputs: Option<Vec<Input>> = target_data
.inputs
.as_ref()
Expand Down
7 changes: 4 additions & 3 deletions packages/nx/src/native/tests/planner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TempFs } from '../../internal-testing-utils/temp-fs';

let tempFs = new TempFs('task-planner');

import { HashPlanner, transferProjectGraph } from '../index';
Expand Down Expand Up @@ -164,10 +165,10 @@ describe('task planner', () => {
{}
);

const planner = new HashPlanner(
nxJson as any,
transferProjectGraph(transformProjectGraphForRust(projectGraph))
const ref = transferProjectGraph(
transformProjectGraphForRust(projectGraph)
);
const planner = new HashPlanner(nxJson as any, ref);

await assertHashPlan(
taskGraph.tasks['parent:build'],
Expand Down

0 comments on commit 09fd1bb

Please sign in to comment.