Skip to content

Commit 43aee87

Browse files
committed
wrapping functions into try catch
1 parent e2c6510 commit 43aee87

File tree

5 files changed

+51
-34
lines changed

5 files changed

+51
-34
lines changed

utils/exec/run-exec.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
import { colors } from "jsr:@cliffy/ansi@^1.0.0-rc.7/colors";
2+
13
export const runExecutable = async (
24
executable: string,
35
args: string[],
46
): Promise<Deno.CommandStatus> => {
5-
const command = await new Deno.Command(executable, {
6-
args,
7-
stdin: "piped",
8-
});
9-
const child = await command.spawn();
10-
const status = await child.status;
7+
try {
8+
const command = await new Deno.Command(executable, {
9+
args,
10+
stdin: "piped",
11+
});
12+
const child = await command.spawn();
13+
const status = await child.status;
1114

12-
return status;
15+
return status;
16+
} catch (error) {
17+
console.error(colors.bgBrightRed(`Error running executable: ${error}`));
18+
Deno.exit(1);
19+
}
1320
};

utils/file/get-dir-path-from-repo.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("getDirPathFromRepo", () => {
1313
expected: "organisation/project",
1414
},
1515
{
16-
repo: "git+https://git-host.com/organisation/project.git",
16+
repo: "git+https://git-host.com/organisation/project.git",
1717
expected: "organisation/project",
1818
},
1919
];

utils/file/get-host-from-repo.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("getHostFromRepo", () => {
1313
expected: "git-host",
1414
},
1515
{
16-
repo: "git+https://git-host.com/organisation/project.git",
16+
repo: "git+https://git-host.com/organisation/project.git",
1717
expected: "git-host",
1818
},
1919
];

utils/git/clone-repo.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@ export const cloneRepo = async (
55
repo: string,
66
localRepo: string,
77
): Promise<void> => {
8-
const git = await findExecutable("git");
8+
try {
9+
const git = await findExecutable("git");
910

10-
const clone = new Deno.Command(git, {
11-
args: ["clone", repo, localRepo],
12-
stdin: "piped",
13-
});
14-
const child = await clone.spawn();
15-
const status = await child.status;
11+
const clone = new Deno.Command(git, {
12+
args: ["clone", repo, localRepo],
13+
stdin: "piped",
14+
});
15+
const child = await clone.spawn();
16+
const status = await child.status;
1617

17-
if (!status.success) {
18-
console.error(colors.bgBrightRed(`Error cloning repository`));
19-
} else {
20-
console.log(
21-
colors.bgBrightGreen(`Repository cloned successfully to ${localRepo}`),
22-
);
18+
if (!status.success) {
19+
console.error(colors.bgBrightRed(`Error cloning repository`));
20+
} else {
21+
console.log(
22+
colors.bgBrightGreen(`Repository cloned successfully to ${localRepo}`),
23+
);
24+
}
25+
} catch (error) {
26+
console.error(colors.bgBrightRed(`Error cloning repository: ${error}`));
27+
Deno.exit(1);
2328
}
2429
};

utils/git/fetch-repo.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@ import { colors } from "jsr:@cliffy/ansi@^1.0.0-rc.7/colors";
22
import { findExecutable } from "../exec/find-exec.ts";
33

44
export const fetchRepo = async (localRepo: string): Promise<void> => {
5-
const git = await findExecutable("git");
5+
try {
6+
const git = await findExecutable("git");
67

7-
const pull = new Deno.Command(git, {
8-
cwd: localRepo,
9-
args: ["fetch", "origin"],
10-
stdin: "piped",
11-
});
12-
const child = await pull.spawn();
13-
const status = await child.status;
8+
const pull = new Deno.Command(git, {
9+
cwd: localRepo,
10+
args: ["fetch", "origin"],
11+
stdin: "piped",
12+
});
13+
const child = await pull.spawn();
14+
const status = await child.status;
1415

15-
if (!status.success) {
16-
console.error(colors.bgBrightRed(`Error fetching repository`));
17-
} else {
18-
console.log(colors.bgBrightGreen(`Repository fetching successfully`));
16+
if (!status.success) {
17+
console.error(colors.bgBrightRed(`Error fetching repository`));
18+
} else {
19+
console.log(colors.bgBrightGreen(`Repository fetching successfully`));
20+
}
21+
} catch (error) {
22+
console.error(colors.bgBrightRed(`Error fetching repository: ${error}`));
23+
Deno.exit(1);
1924
}
2025
};

0 commit comments

Comments
 (0)