mirror of
https://github.com/github/codeql-action.git
synced 2025-12-27 09:40:17 +08:00
Improve error handling for ending tracing
This commit is contained in:
@@ -26,21 +26,30 @@ export async function endTracingForCluster(
|
||||
// If there are no traced languages, we don't need to do anything.
|
||||
if (!config.languages.some(isTracedLanguage)) return;
|
||||
|
||||
const endTracingEnvVariables: Map<string, string | null> = JSON.parse(
|
||||
fs.readFileSync(
|
||||
path.resolve(
|
||||
config.dbLocation,
|
||||
"temp/tracingEnvironment/end-tracing.json"
|
||||
),
|
||||
"utf8"
|
||||
)
|
||||
const envVariablesFile = path.resolve(
|
||||
config.dbLocation,
|
||||
"temp/tracingEnvironment/end-tracing.json"
|
||||
);
|
||||
for (const [key, value] of Object.entries(endTracingEnvVariables)) {
|
||||
if (value !== null) {
|
||||
process.env[key] = value;
|
||||
} else {
|
||||
delete process.env[key];
|
||||
if (!fs.existsSync(envVariablesFile)) {
|
||||
throw new Error(
|
||||
`Environment file for ending tracing not found: ${envVariablesFile}`
|
||||
);
|
||||
}
|
||||
try {
|
||||
const endTracingEnvVariables: Map<string, string | null> = JSON.parse(
|
||||
fs.readFileSync(envVariablesFile, "utf8")
|
||||
);
|
||||
for (const [key, value] of Object.entries(endTracingEnvVariables)) {
|
||||
if (value !== null) {
|
||||
process.env[key] = value;
|
||||
} else {
|
||||
delete process.env[key];
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
`Failed to parse file containing end tracing environment variables: ${e}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user