Skip to content

Fail more clearly if the file program is not installed on the runner #2234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 15, 2024
Prev Previous commit
Next Next commit
Emit diagnostic if file is not installed
  • Loading branch information
mbg committed Apr 11, 2024
commit 1829b70201ca913e6f6663e6442aad717acab421
11 changes: 9 additions & 2 deletions lib/actions-util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/actions-util.js.map

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions lib/init-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action.js.map

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/actions-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,14 @@ export function getWorkflowRunAttempt(): number {
return workflowRunAttempt;
}

export class FileCmdNotFoundError extends Error {
constructor(msg: string) {
super(msg);

this.name = "FileCmdNotFoundError";
}
}

/**
* Tries to obtain the output of the `file` command for the file at the specified path.
* The output will vary depending on the type of `file`, which operating system we are running on, etc.
Expand All @@ -442,7 +450,9 @@ export const getFileType = async (filePath: string): Promise<string> => {
core.info(
"The `file` program is required, but does not appear to be installed. Please install it.",
);
throw e;
throw new FileCmdNotFoundError(
`The \`file\` program is not installed: ${e}`,
);
}

try {
Expand Down
23 changes: 23 additions & 0 deletions src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { safeWhich } from "@chrisgavin/safe-which";
import { v4 as uuidV4 } from "uuid";

import {
FileCmdNotFoundError,
getActionVersion,
getFileType,
getOptionalInput,
Expand All @@ -15,6 +16,7 @@ import {
import { getGitHubVersion } from "./api-client";
import { CodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
import { EnvVar } from "./environment";
import { Feature, Features } from "./feature-flags";
import { checkInstallPython311, initCodeQL, initConfig, runInit } from "./init";
Expand Down Expand Up @@ -372,6 +374,27 @@ async function run() {
logger.warning(
`Failed to determine the location of the Go binary: ${e}`,
);

if (e instanceof FileCmdNotFoundError) {
addDiagnostic(
config,
Language.go,
makeDiagnostic(
"go/workflow/file-program-unavailable",
"The `file` program is required, but does not appear to be installed",
{
markdownMessage:
"CodeQL was unable to find the `file` program on this system. Ensure that the `file` program is installed on the runner and accessible.",
visibility: {
statusPage: true,
telemetry: true,
cliSummaryTable: true,
},
severity: "warning",
},
),
);
}
}
}

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy