Skip to content

Commit 1c3ef85

Browse files
AgentEnderFrozenPandaz
authored andcommitted
fix(core): handle null outputs in native cache (#30398)
<!-- 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` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior `cache.rs` expects outputs to always be an array ## Expected Behavior `cache.rs` is able to handle null ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # (cherry picked from commit 46d55ad)
1 parent 8db4489 commit 1c3ef85

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

packages/nx/src/native/cache/cache.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl NxCache {
175175
&self,
176176
hash: String,
177177
result: CachedResult,
178-
outputs: Vec<String>,
178+
outputs: Option<Vec<String>>,
179179
) -> anyhow::Result<()> {
180180
trace!(
181181
"applying remote cache results: {:?} ({})",
@@ -184,9 +184,12 @@ impl NxCache {
184184
);
185185
let terminal_output = result.terminal_output.clone();
186186
let mut size = terminal_output.len() as i64;
187-
if outputs.len() > 0 && result.code == 0 {
188-
size += try_and_retry(|| self.copy_files_from_cache(result.clone(), outputs.clone()))?;
189-
};
187+
if let Some(outputs) = outputs {
188+
if outputs.len() > 0 && result.code == 0 {
189+
size +=
190+
try_and_retry(|| self.copy_files_from_cache(result.clone(), outputs.clone()))?;
191+
};
192+
}
190193
write(self.get_task_outputs_path(hash.clone()), terminal_output)?;
191194

192195
let code: i16 = result.code;

packages/nx/src/native/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export declare class NxCache {
4040
constructor(workspaceRoot: string, cachePath: string, dbConnection: ExternalObject<NxDbConnection>, linkTaskDetails?: boolean | undefined | null, maxCacheSize?: number | undefined | null)
4141
get(hash: string): CachedResult | null
4242
put(hash: string, terminalOutput: string, outputs: Array<string>, code: number): void
43-
applyRemoteCacheResults(hash: string, result: CachedResult, outputs: Array<string>): void
43+
applyRemoteCacheResults(hash: string, result: CachedResult, outputs?: Array<string> | undefined | null): void
4444
getTaskOutputsPath(hash: string): string
4545
getCacheSize(): number
4646
copyFilesFromCache(cachedResult: CachedResult, outputs: Array<string>): number

0 commit comments

Comments
 (0)