fix: improve error handling and logging for diff range path resolution

This commit is contained in:
Sam Robson
2026-03-25 19:49:42 +00:00
parent d5bb39fa0b
commit 23a0098b57
11 changed files with 169 additions and 26 deletions
+15 -1
View File
@@ -162327,10 +162327,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) {
}
async function getDiffRangeFilePaths(sourceRoot, logger) {
const jsonFilePath = getDiffRangesJsonFilePath();
if (!fs2.existsSync(jsonFilePath)) {
logger.debug(
`No diff ranges JSON file found at ${jsonFilePath}; skipping.`
);
return [];
}
let contents;
try {
contents = await fs2.promises.readFile(jsonFilePath, "utf8");
} catch {
} catch (e) {
logger.warning(
`Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}`
);
return [];
}
let diffRanges;
@@ -162347,6 +162356,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) {
);
const repoRoot = await getGitRoot(sourceRoot);
if (repoRoot === void 0) {
if (getOptionalInput("source-root")) {
throw new Error(
"Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis."
);
}
logger.warning(
"Cannot determine git root; returning diff range paths as-is."
);
+15 -1
View File
@@ -107922,10 +107922,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) {
}
async function getDiffRangeFilePaths(sourceRoot, logger) {
const jsonFilePath = getDiffRangesJsonFilePath();
if (!fs3.existsSync(jsonFilePath)) {
logger.debug(
`No diff ranges JSON file found at ${jsonFilePath}; skipping.`
);
return [];
}
let contents;
try {
contents = await fs3.promises.readFile(jsonFilePath, "utf8");
} catch {
} catch (e) {
logger.warning(
`Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}`
);
return [];
}
let diffRanges;
@@ -107942,6 +107951,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) {
);
const repoRoot = await getGitRoot(sourceRoot);
if (repoRoot === void 0) {
if (getOptionalInput("source-root")) {
throw new Error(
"Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis."
);
}
logger.warning(
"Cannot determine git root; returning diff range paths as-is."
);
+15 -1
View File
@@ -104381,10 +104381,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) {
}
async function getDiffRangeFilePaths(sourceRoot, logger) {
const jsonFilePath = getDiffRangesJsonFilePath();
if (!fs2.existsSync(jsonFilePath)) {
logger.debug(
`No diff ranges JSON file found at ${jsonFilePath}; skipping.`
);
return [];
}
let contents;
try {
contents = await fs2.promises.readFile(jsonFilePath, "utf8");
} catch {
} catch (e) {
logger.warning(
`Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}`
);
return [];
}
let diffRanges;
@@ -104401,6 +104410,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) {
);
const repoRoot = await getGitRoot(sourceRoot);
if (repoRoot === void 0) {
if (getOptionalInput("source-root")) {
throw new Error(
"Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis."
);
}
logger.warning(
"Cannot determine git root; returning diff range paths as-is."
);
+15 -1
View File
@@ -165839,10 +165839,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) {
}
async function getDiffRangeFilePaths(sourceRoot, logger) {
const jsonFilePath = getDiffRangesJsonFilePath();
if (!fs3.existsSync(jsonFilePath)) {
logger.debug(
`No diff ranges JSON file found at ${jsonFilePath}; skipping.`
);
return [];
}
let contents;
try {
contents = await fs3.promises.readFile(jsonFilePath, "utf8");
} catch {
} catch (e) {
logger.warning(
`Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}`
);
return [];
}
let diffRanges;
@@ -165859,6 +165868,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) {
);
const repoRoot = await getGitRoot(sourceRoot);
if (repoRoot === void 0) {
if (getOptionalInput("source-root")) {
throw new Error(
"Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis."
);
}
logger.warning(
"Cannot determine git root; returning diff range paths as-is."
);
+23 -9
View File
@@ -105491,10 +105491,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) {
}
async function getDiffRangeFilePaths(sourceRoot, logger) {
const jsonFilePath = getDiffRangesJsonFilePath();
if (!fs3.existsSync(jsonFilePath)) {
logger.debug(
`No diff ranges JSON file found at ${jsonFilePath}; skipping.`
);
return [];
}
let contents;
try {
contents = await fs3.promises.readFile(jsonFilePath, "utf8");
} catch {
} catch (e) {
logger.warning(
`Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}`
);
return [];
}
let diffRanges;
@@ -105511,6 +105520,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) {
);
const repoRoot = await getGitRoot(sourceRoot);
if (repoRoot === void 0) {
if (getOptionalInput("source-root")) {
throw new Error(
"Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis."
);
}
logger.warning(
"Cannot determine git root; returning diff range paths as-is."
);
@@ -110588,8 +110602,8 @@ async function loadRepositoryProperties(repositoryNwo, logger) {
}
}
async function computeAndPersistDiffRanges(codeql, features, logger) {
try {
await withGroupAsync("Compute PR diff ranges", async () => {
await withGroupAsync("Computing PR diff ranges", async () => {
try {
const branches = await getDiffInformedAnalysisBranches(
codeql,
features,
@@ -110607,12 +110621,12 @@ async function computeAndPersistDiffRanges(codeql, features, logger) {
logger.info(
`Persisted ${ranges.length} diff range(s) across ${distinctFiles} file(s).`
);
});
} catch (e) {
logger.warning(
`Failed to compute and persist PR diff ranges: ${getErrorMessage(e)}`
);
}
} catch (e) {
logger.warning(
`Failed to compute and persist PR diff ranges: ${getErrorMessage(e)}`
);
}
});
}
async function recordZstdAvailability(config, zstdAvailability) {
addNoLanguageDiagnostic(
+15 -1
View File
@@ -104374,10 +104374,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) {
}
async function getDiffRangeFilePaths(sourceRoot, logger) {
const jsonFilePath = getDiffRangesJsonFilePath();
if (!fs2.existsSync(jsonFilePath)) {
logger.debug(
`No diff ranges JSON file found at ${jsonFilePath}; skipping.`
);
return [];
}
let contents;
try {
contents = await fs2.promises.readFile(jsonFilePath, "utf8");
} catch {
} catch (e) {
logger.warning(
`Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}`
);
return [];
}
let diffRanges;
@@ -104394,6 +104403,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) {
);
const repoRoot = await getGitRoot(sourceRoot);
if (repoRoot === void 0) {
if (getOptionalInput("source-root")) {
throw new Error(
"Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis."
);
}
logger.warning(
"Cannot determine git root; returning diff range paths as-is."
);
+15 -1
View File
@@ -104265,10 +104265,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) {
}
async function getDiffRangeFilePaths(sourceRoot, logger) {
const jsonFilePath = getDiffRangesJsonFilePath();
if (!fs3.existsSync(jsonFilePath)) {
logger.debug(
`No diff ranges JSON file found at ${jsonFilePath}; skipping.`
);
return [];
}
let contents;
try {
contents = await fs3.promises.readFile(jsonFilePath, "utf8");
} catch {
} catch (e) {
logger.warning(
`Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}`
);
return [];
}
let diffRanges;
@@ -104285,6 +104294,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) {
);
const repoRoot = await getGitRoot(sourceRoot);
if (repoRoot === void 0) {
if (getOptionalInput("source-root")) {
throw new Error(
"Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis."
);
}
logger.warning(
"Cannot determine git root; returning diff range paths as-is."
);
+15 -1
View File
@@ -107530,10 +107530,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) {
}
async function getDiffRangeFilePaths(sourceRoot, logger) {
const jsonFilePath = getDiffRangesJsonFilePath();
if (!fs3.existsSync(jsonFilePath)) {
logger.debug(
`No diff ranges JSON file found at ${jsonFilePath}; skipping.`
);
return [];
}
let contents;
try {
contents = await fs3.promises.readFile(jsonFilePath, "utf8");
} catch {
} catch (e) {
logger.warning(
`Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}`
);
return [];
}
let diffRanges;
@@ -107550,6 +107559,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) {
);
const repoRoot = await getGitRoot(sourceRoot);
if (repoRoot === void 0) {
if (getOptionalInput("source-root")) {
throw new Error(
"Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis."
);
}
logger.warning(
"Cannot determine git root; returning diff range paths as-is."
);
+15 -1
View File
@@ -107240,10 +107240,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) {
}
async function getDiffRangeFilePaths(sourceRoot, logger) {
const jsonFilePath = getDiffRangesJsonFilePath();
if (!fs3.existsSync(jsonFilePath)) {
logger.debug(
`No diff ranges JSON file found at ${jsonFilePath}; skipping.`
);
return [];
}
let contents;
try {
contents = await fs3.promises.readFile(jsonFilePath, "utf8");
} catch {
} catch (e) {
logger.warning(
`Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}`
);
return [];
}
let diffRanges;
@@ -107260,6 +107269,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) {
);
const repoRoot = await getGitRoot(sourceRoot);
if (repoRoot === void 0) {
if (getOptionalInput("source-root")) {
throw new Error(
"Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis."
);
}
logger.warning(
"Cannot determine git root; returning diff range paths as-is."
);