Skip to content

Commit 19aa55d

Browse files
committed
Log error in getTracerConfigForCluster instead of re-throwing it
1 parent aa2cb99 commit 19aa55d

4 files changed

Lines changed: 26 additions & 11 deletions

File tree

‎lib/entry-points.js‎

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

‎src/init-action.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ async function run(
716716
);
717717
}
718718

719-
const tracerConfig = await getCombinedTracerConfig(codeql, config);
719+
const tracerConfig = await getCombinedTracerConfig(logger, codeql, config);
720720
if (tracerConfig !== undefined) {
721721
for (const [key, value] of Object.entries(tracerConfig.env)) {
722722
core.exportVariable(key, value);

‎src/tracer-config.test.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import * as sinon from "sinon";
77
import { CodeQL, getCodeQLForTesting } from "./codeql";
88
import * as configUtils from "./config-utils";
99
import { BuiltInLanguage } from "./languages";
10-
import { createTestConfig, makeVersionInfo, setupTests } from "./testing-utils";
10+
import {
11+
createTestConfig,
12+
makeVersionInfo,
13+
RecordingLogger,
14+
setupTests,
15+
} from "./testing-utils";
1116
import { ToolsFeature } from "./tools-features";
1217
import { getCombinedTracerConfig } from "./tracer-config";
1318
import * as util from "./util";
@@ -42,18 +47,20 @@ async function stubCodeql(
4247
}
4348

4449
test("getCombinedTracerConfig - return undefined when no languages are traced languages", async (t) => {
50+
const logger = new RecordingLogger();
4551
await util.withTmpDir(async (tmpDir) => {
4652
const config = getTestConfig(tmpDir);
4753
// No traced languages
4854
config.languages = [BuiltInLanguage.javascript, BuiltInLanguage.python];
4955
t.deepEqual(
50-
await getCombinedTracerConfig(await stubCodeql(), config),
56+
await getCombinedTracerConfig(logger, await stubCodeql(), config),
5157
undefined,
5258
);
5359
});
5460
});
5561

5662
test("getCombinedTracerConfig", async (t) => {
63+
const logger = new RecordingLogger();
5764
await util.withTmpDir(async (tmpDir) => {
5865
const config = getTestConfig(tmpDir);
5966

@@ -82,7 +89,11 @@ test("getCombinedTracerConfig", async (t) => {
8289
);
8390
fs.writeFileSync(startTracingJson, JSON.stringify(startTracingEnv));
8491

85-
const result = await getCombinedTracerConfig(await stubCodeql(), config);
92+
const result = await getCombinedTracerConfig(
93+
logger,
94+
await stubCodeql(),
95+
config,
96+
);
8697
t.notDeepEqual(result, undefined);
8798

8899
t.false(Object.prototype.hasOwnProperty.call(result?.env, "CODEQL_RUNNER"));

‎src/tracer-config.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export async function endTracingForCluster(
7777
}
7878

7979
async function getTracerConfigForCluster(
80+
logger: Logger,
8081
config: Config,
8182
): Promise<TracerConfig> {
8283
const filePath = path.resolve(
@@ -89,19 +90,21 @@ async function getTracerConfigForCluster(
8990
env: tracingEnvVariables,
9091
};
9192
} catch (err) {
92-
throw new Error(
93+
logger.error(
9394
`Failed to parse tracing environment from '${filePath}': ${getErrorMessage(err)}`,
9495
);
96+
throw new Error(`Failed to parse tracing environment from '${filePath}'.`);
9597
}
9698
}
9799

98100
export async function getCombinedTracerConfig(
101+
logger: Logger,
99102
codeql: CodeQL,
100103
config: Config,
101104
): Promise<TracerConfig | undefined> {
102105
if (!(await shouldEnableIndirectTracing(codeql, config))) {
103106
return undefined;
104107
}
105108

106-
return await getTracerConfigForCluster(config);
109+
return await getTracerConfigForCluster(logger, config);
107110
}

0 commit comments

Comments
 (0)