Skip to content

Commit 23a09cb

Browse files
committed
chore: make ubuntuVersion exception safe
1 parent b9c2f3b commit 23a09cb

10 files changed

+30
-17
lines changed

dist/node12/actions_python.54e91387.js

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

dist/node12/actions_python.54e91387.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node12/setup_cpp.js

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

dist/node12/setup_cpp.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node16/actions_python.b4fff571.js

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

dist/node16/actions_python.b4fff571.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node16/setup_cpp.js

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

dist/node16/setup_cpp.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,7 @@ export async function main(args: string[]): Promise<number> {
148148

149149
// installing the specified tools
150150

151-
let osVersion: number[] | null = null
152-
try {
153-
// get the version if not already done
154-
osVersion = await ubuntuVersion()
155-
} catch (err) {
156-
warning((err as Error).toString())
157-
}
151+
const osVersion = await ubuntuVersion()
158152

159153
// sync the version for the llvm tools
160154
if (!syncVersions(opts, ["llvm", "clangtidy", "clangformat"])) {

src/utils/env/ubuntu_version.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1+
import { warning } from "ci-log"
12
import { getUbuntuVersion } from "ubuntu-version"
23
import which from "which"
34
import { setupAptPack } from "../setup/setupAptPack"
45
import { isUbuntu } from "./isUbuntu"
56

67
export async function ubuntuVersion(): Promise<number[] | null> {
7-
if (isUbuntu()) {
8-
if (which.sync("lsb_release", { nothrow: true }) === null) {
9-
await setupAptPack("lsb-release")
10-
}
11-
const versionSplitted = await getUbuntuVersion()
8+
try {
9+
if (isUbuntu()) {
10+
if (which.sync("lsb_release", { nothrow: true }) === null) {
11+
await setupAptPack("lsb-release")
12+
}
13+
const versionSplitted = await getUbuntuVersion()
1214

13-
if (versionSplitted.length === 0) {
14-
throw new Error("Failed to get the ubuntu major version.")
15-
}
15+
if (versionSplitted.length === 0) {
16+
warning("Failed to get the ubuntu major version.")
17+
return null
18+
}
1619

17-
return versionSplitted
18-
} else {
20+
return versionSplitted
21+
} else {
22+
return null
23+
}
24+
} catch (err) {
25+
warning((err as Error).toString())
1926
return null
2027
}
2128
}

0 commit comments

Comments
 (0)