Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion actions/setup/js/create_code_scanning_alert.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const { getErrorMessage } = require("./error_helpers.cjs");
const { logStagedPreviewInfo } = require("./staged_preview.cjs");
const { isStagedMode } = require("./safe_output_helpers.cjs");
const { ERR_SYSTEM } = require("./error_codes.cjs");
const fs = require("fs");
const path = require("path");

Expand Down Expand Up @@ -89,7 +90,7 @@ async function main(config = {}) {
try {
fs.writeFileSync(sarifFilePath, JSON.stringify(sarifContent, null, 2));
} catch (err) {
throw new Error(`Failed to write file ${sarifFilePath}: ${String(err)}`, { cause: err });
throw new Error(`${ERR_SYSTEM}: Failed to write file ${sarifFilePath}: ${String(err)}`, { cause: err });
}
core.info(`✓ Updated SARIF file with ${validFindings.length} finding(s): ${sarifFilePath}`);
}
Expand Down
9 changes: 5 additions & 4 deletions actions/setup/js/load_experiment_state_from_repo.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
const fs = require("fs");
const path = require("path");
const { getErrorMessage } = require("./error_helpers.cjs");
const { ERR_SYSTEM, ERR_API } = require("./error_codes.cjs");

const MAX_STATE_FILE_BYTES = 102400;
// Keep this allowlist aligned with actions/setup/js/normalize_branch_name.cjs valid characters.
Expand Down Expand Up @@ -99,7 +100,7 @@ async function fetchFileFromBranch(octokit, owner, repo, branch, filePath) {
if (errAny.status === 404) {
return null;
}
throw err;
throw new Error(`${ERR_API}: Failed to fetch file "${filePath}" from branch "${branch}": ${String(err)}`, { cause: err });
}
}

Expand All @@ -119,7 +120,7 @@ async function main() {
try {
fs.mkdirSync(stateDir, { recursive: true });
} catch (err) {
throw new Error(`Failed to create directory ${stateDir}: ${String(err)}`, { cause: err });
throw new Error(`${ERR_SYSTEM}: Failed to create directory ${stateDir}: ${String(err)}`, { cause: err });
}
return;
}
Expand All @@ -143,7 +144,7 @@ async function main() {
try {
fs.mkdirSync(stateDir, { recursive: true });
} catch (err) {
throw new Error(`Failed to create directory ${stateDir}: ${String(err)}`, { cause: err });
throw new Error(`${ERR_SYSTEM}: Failed to create directory ${stateDir}: ${String(err)}`, { cause: err });
}

if (content === null) {
Expand Down Expand Up @@ -171,7 +172,7 @@ async function main() {
try {
fs.writeFileSync(stateFile, content, "utf8");
} catch (err) {
throw new Error(`Failed to write file ${stateFile}: ${String(err)}`, { cause: err });
throw new Error(`${ERR_SYSTEM}: Failed to write file ${stateFile}: ${String(err)}`, { cause: err });
}
core.info(`Experiment state written to ${stateFile}`);
}
Expand Down
3 changes: 2 additions & 1 deletion actions/setup/js/safe_outputs_bootstrap.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
const fs = require("fs");
const { loadConfig } = require("./safe_outputs_config.cjs");
const { loadTools } = require("./safe_outputs_tools_loader.cjs");
const { ERR_CONFIG } = require("./error_codes.cjs");

/**
* @typedef {Object} Logger
Expand Down Expand Up @@ -68,7 +69,7 @@ function enforceCreatePullRequestRuntimePolicy(config, logger) {

const message = `create-pull-request is disabled by runtime policy: ${policyVarName}=false. ` + `Remove safe-outputs.create-pull-request or set ${policyVarName}=true.`;
logger.debugError(message);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/diagnosing-bugs] The debugError call logs message without the ERR_CONFIG: prefix, but the thrown error includes it — so logs and the exception message will differ, complicating post-hoc debugging.

💡 Suggested fix

Log the prefixed form so that the debug output is consistent with the thrown error:

const message = `create-pull-request is disabled by runtime policy: ${policyVarName}=false. ` +
  `Remove safe-outputs.create-pull-request or set ${policyVarName}=true.`;
const prefixed = `${ERR_CONFIG}: ${message}`;
logger.debugError(prefixed);
throw new Error(prefixed);

When a consumer catches the error and compares it to a log line, both should carry the same ERR_CONFIG: prefix.

@copilot please address this.

throw new Error(message);
throw new Error(`${ERR_CONFIG}: ${message}`);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion actions/setup/js/safe_outputs_config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { getErrorMessage } = require("./error_helpers.cjs");
const { redactSensitiveConfig } = require("./safe_outputs_config_redact.cjs");
const { ERR_SYSTEM } = require("./error_codes.cjs");

const fs = require("fs");
const path = require("path");
Expand Down Expand Up @@ -73,7 +74,7 @@ function loadConfig(server) {
try {
fs.mkdirSync(outputDir, { recursive: true });
} catch (err) {
throw new Error(`Failed to create directory ${outputDir}: ${String(err)}`, { cause: err });
throw new Error(`${ERR_SYSTEM}: Failed to create directory ${outputDir}: ${String(err)}`, { cause: err });
}
}

Expand Down
Loading