chore: make ubuntuVersion exception safe

This commit is contained in:
Amin Yahyaabadi 2022-11-02 20:06:36 -07:00
parent b9c2f3b391
commit 23a09cba35
10 changed files with 30 additions and 17 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/node12/setup_cpp.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/node12/setup_cpp.js.map vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/node16/setup_cpp.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/node16/setup_cpp.js.map vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -148,13 +148,7 @@ export async function main(args: string[]): Promise<number> {
// installing the specified tools
let osVersion: number[] | null = null
try {
// get the version if not already done
osVersion = await ubuntuVersion()
} catch (err) {
warning((err as Error).toString())
}
const osVersion = await ubuntuVersion()
// sync the version for the llvm tools
if (!syncVersions(opts, ["llvm", "clangtidy", "clangformat"])) {

View File

@ -1,21 +1,28 @@
import { warning } from "ci-log"
import { getUbuntuVersion } from "ubuntu-version"
import which from "which"
import { setupAptPack } from "../setup/setupAptPack"
import { isUbuntu } from "./isUbuntu"
export async function ubuntuVersion(): Promise<number[] | null> {
if (isUbuntu()) {
if (which.sync("lsb_release", { nothrow: true }) === null) {
await setupAptPack("lsb-release")
}
const versionSplitted = await getUbuntuVersion()
try {
if (isUbuntu()) {
if (which.sync("lsb_release", { nothrow: true }) === null) {
await setupAptPack("lsb-release")
}
const versionSplitted = await getUbuntuVersion()
if (versionSplitted.length === 0) {
throw new Error("Failed to get the ubuntu major version.")
}
if (versionSplitted.length === 0) {
warning("Failed to get the ubuntu major version.")
return null
}
return versionSplitted
} else {
return versionSplitted
} else {
return null
}
} catch (err) {
warning((err as Error).toString())
return null
}
}