summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-07-31 16:07:48 +0200
committerAylur <[email protected]>2024-07-31 16:07:48 +0200
commitf86a908952c5ae34a0e2ac832ffe43cb4d0ae0cc (patch)
treebad3930239b61d6cbbbdd202f296756c034c9beb
parente398c9f997935d04835df387b6bc40bdf7a87910 (diff)
fix(process): exec
throw stdout as error
-rw-r--r--gjs/src/process.ts22
-rw-r--r--src/process.vala9
2 files changed, 7 insertions, 24 deletions
diff --git a/gjs/src/process.ts b/gjs/src/process.ts
index f7ff7b0..577ad99 100644
--- a/gjs/src/process.ts
+++ b/gjs/src/process.ts
@@ -1,4 +1,4 @@
-import { Astal } from "./imports.js"
+import { Astal, GLib } from "./imports.js"
type Args<Out = void, Err = void> = {
cmd: string | string[]
@@ -36,23 +36,11 @@ export function subprocess(
return proc
}
-export function exec<Out = string, Err = string>(
- args: Args<Out, Err>
-): Out | Err
-export function exec<Out = string, Err = string>(
- cmd: string | string[],
- onOut?: (stdout: string) => Out,
- onErr?: (stderr: string) => Err,
-): Out | Err
-export function exec<Out = string, Err = string>(
- argsOrCmd: Args<Out, Err> | string | string[],
- onOut: (stdout: string) => Out = out => out as Out,
- onErr: (stderr: string) => Err = out => out as Err,
-): Out | Err {
- const { cmd, err, out } = args(argsOrCmd, onOut, onErr)
+/** @throws {GLib.Error} Throws stderr */
+export function exec(cmd: string | string[]) {
return Array.isArray(cmd)
- ? out(Astal.Process.execv(cmd)!) as Out
- : err(Astal.Process.exec(cmd)!) as Err
+ ? Astal.Process.execv(cmd)
+ : Astal.Process.exec(cmd)
}
export function execAsync(cmd: string | string[]): Promise<string> {
diff --git a/src/process.vala b/src/process.vala
index 6e63264..040c44d 100644
--- a/src/process.vala
+++ b/src/process.vala
@@ -1,5 +1,4 @@
-namespace Astal {
-public class Process : Object {
+public class Astal.Process : Object {
private void read_stream(DataInputStream stream, bool err) {
stream.read_line_utf8_async.begin(Priority.DEFAULT, null, (_, res) => {
try {
@@ -82,7 +81,7 @@ public class Process : Object {
if (success)
return out_str.strip();
else
- throw new ProcessError.FAILED(err_str.strip());
+ throw new IOError.FAILED(err_str.strip());
}
public static string exec(string cmd) throws Error {
@@ -120,7 +119,3 @@ public class Process : Object {
return new Process.exec_asyncv(argv);
}
}
-errordomain ProcessError {
- FAILED
-}
-}