Skip to content

Commit c56f48e

Browse files
committed
Log unexpected conditions during caching CLI output
1 parent aa0eadc commit c56f48e

5 files changed

Lines changed: 33 additions & 16 deletions

File tree

lib/entry-points.js

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli/output-cache.test.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import path from "path";
44
import test from "ava";
55

66
import { EnvVar } from "../environment";
7+
import { getRunnerLogger } from "../logging";
78
import { getTestEnv, setupTests } from "../testing-utils";
89
import * as util from "../util";
910

1011
import * as outputCache from "./output-cache";
1112

1213
setupTests(test);
1314

15+
const logger = getRunnerLogger(true);
16+
1417
test.serial(
1518
"getCachedCodeQlVersion reuses a version persisted by an earlier step",
1619
async (t) => {
@@ -25,9 +28,12 @@ test.serial(
2528
"utf8",
2629
);
2730
const env = getTestEnv({ [EnvVar.TEMP]: tmpDir });
28-
t.deepEqual(outputCache.getCachedCodeQlVersion(env, "/path/to/codeql"), {
29-
version: "2.20.0",
30-
});
31+
t.deepEqual(
32+
outputCache.getCachedCodeQlVersion(logger, env, "/path/to/codeql"),
33+
{
34+
version: "2.20.0",
35+
},
36+
);
3137
});
3238
},
3339
);
@@ -47,7 +53,7 @@ test.serial(
4753
);
4854
const env = getTestEnv({ [EnvVar.TEMP]: tmpDir });
4955
t.is(
50-
outputCache.getCachedCodeQlVersion(env, "/path/to/codeql"),
56+
outputCache.getCachedCodeQlVersion(logger, env, "/path/to/codeql"),
5157
undefined,
5258
);
5359
});
@@ -62,7 +68,7 @@ test.serial(
6268
fs.writeFileSync(cacheFile, "not valid json", "utf8");
6369
const env = getTestEnv({ [EnvVar.TEMP]: tmpDir });
6470
t.is(
65-
outputCache.getCachedCodeQlVersion(env, "/path/to/codeql"),
71+
outputCache.getCachedCodeQlVersion(logger, env, "/path/to/codeql"),
6672
undefined,
6773
);
6874
});
@@ -100,7 +106,7 @@ test.serial(
100106
for (const value of testValues) {
101107
fs.writeFileSync(cacheFile, value, "utf8");
102108
t.is(
103-
outputCache.getCachedCodeQlVersion(env, "/path/to/codeql"),
109+
outputCache.getCachedCodeQlVersion(logger, env, "/path/to/codeql"),
104110
undefined,
105111
value,
106112
);
@@ -114,7 +120,7 @@ test.serial("getCachedCodeQlVersion ignores non-existent file", async (t) => {
114120
const env = getTestEnv({ [EnvVar.TEMP]: tmpDir });
115121
t.notThrows(() => {
116122
t.is(
117-
outputCache.getCachedCodeQlVersion(env, "/path/to/codeql"),
123+
outputCache.getCachedCodeQlVersion(logger, env, "/path/to/codeql"),
118124
undefined,
119125
);
120126
});

src/cli/output-cache.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from "path";
33

44
import { getTemporaryDirectory } from "../actions-util";
55
import { Env } from "../environment";
6+
import { Logger } from "../logging";
67

78
import type { VersionInfo } from "./types";
89

@@ -78,10 +79,12 @@ export function cacheCodeQlVersion(
7879

7980
/**
8081
* Returns the cached CodeQL CLI version, if any.
82+
* @param logger The logger to use for logging messages.
8183
* @param env The environment variables to use.
8284
* @param cmd The path to the CodeQL CLI.
8385
*/
8486
export function getCachedCodeQlVersion(
87+
logger: Logger,
8588
env: Env,
8689
cmd?: string,
8790
): undefined | VersionInfo {
@@ -94,13 +97,17 @@ export function getCachedCodeQlVersion(
9497
let serialized: string;
9598
try {
9699
serialized = fs.readFileSync(getCommandCacheFilePath(env), "utf8");
97-
} catch {
100+
} catch (e) {
101+
logger.debug(
102+
`Cannot read CLI-cache file ${getCommandCacheFilePath(env)}: ${e}`,
103+
);
98104
return undefined;
99105
}
100106
let persisted: unknown;
101107
try {
102108
persisted = JSON.parse(serialized);
103-
} catch {
109+
} catch (e) {
110+
logger.debug(`Cannot parse CLI-cache data as JSON: ${e}`);
104111
return undefined;
105112
}
106113
if (

src/codeql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ async function getCodeQLForCmd(
491491
return cmd;
492492
},
493493
async getVersion() {
494-
let result = outputCache.getCachedCodeQlVersion(getEnv(), cmd);
494+
let result = outputCache.getCachedCodeQlVersion(logger, getEnv(), cmd);
495495
if (result === undefined) {
496496
result = await runCliJson<VersionInfo>(
497497
cmd,

src/status-report.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ export async function createStatusReportBase(
376376
core.exportVariable(EnvVar.WORKFLOW_STARTED_AT, workflowStartedAt);
377377
}
378378
const runnerOs = getRequiredEnvParam("RUNNER_OS");
379-
const codeQlCliVersion = getCachedCodeQlVersion(getEnv());
379+
const codeQlCliVersion = getCachedCodeQlVersion(logger, getEnv());
380380
const actionRef = process.env["GITHUB_ACTION_REF"] || "";
381381
const testingEnvironment = getTestingEnvironment();
382382
// re-export the testing environment variable so that it is available to subsequent steps,

0 commit comments

Comments
 (0)