summaryrefslogtreecommitdiff
path: root/u/process/run.ts
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2025-05-18 22:54:15 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2025-05-18 22:55:20 -0700
commitd54e91c6582ed160cf2f2fcf977e48b4439d133b (patch)
tree5669367c4fa49bc0373b0c581ea3027218fd5e32 /u/process/run.ts
parent9cf3fc0259730b7dcf47b3ab4a04369e39fb4614 (diff)
downloadci-theBigRefactor.tar.gz
ci-theBigRefactor.zip
Diffstat (limited to 'u/process/run.ts')
-rw-r--r--u/process/run.ts33
1 files changed, 17 insertions, 16 deletions
diff --git a/u/process/run.ts b/u/process/run.ts
index cbf8c65..4954438 100644
--- a/u/process/run.ts
+++ b/u/process/run.ts
@@ -6,21 +6,21 @@ import {
TraceUtil,
} from "@emprespresso/pengueno";
-type Command = string[] | string;
+export type Command = string[] | string;
type CommandOutputDecoded = {
code: number;
stdoutText: string;
stderrText: string;
};
-export class ProcessError extends Error {}
export const getStdout = <Trace>(
c: ITraceable<Command, Trace>,
options: Deno.CommandOptions = {},
-): Promise<IEither<ProcessError, string>> =>
+): Promise<IEither<Error, string>> =>
c.bimap(TraceUtil.withFunctionTrace(getStdout))
- .map(({ item: cmd, trace }) => {
- trace.trace(`:> im gonna run this command! ${cmd}`);
+ .map((tCmd) => {
+ const cmd = tCmd.get();
+ tCmd.trace.trace(`:> im gonna run this command! ${cmd}`);
const [exec, ...args] = (typeof cmd === "string") ? cmd.split(" ") : cmd;
return new Deno.Command(exec, {
args,
@@ -29,12 +29,12 @@ export const getStdout = <Trace>(
...options,
}).output();
})
- .map(({ item: p }) =>
- Either.fromFailableAsync<Error, Deno.CommandOutput>(p)
+ .map((tOut) =>
+ Either.fromFailableAsync<Error, Deno.CommandOutput>(tOut.get())
)
.map(
- TraceUtil.promiseify(({ item: eitherOutput, trace }) =>
- eitherOutput.flatMap(({ code, stderr, stdout }) =>
+ TraceUtil.promiseify((tEitherOut) =>
+ tEitherOut.get().flatMap(({ code, stderr, stdout }) =>
Either
.fromFailable<Error, CommandOutputDecoded>(() => {
const stdoutText = new TextDecoder().decode(stdout);
@@ -42,22 +42,23 @@ export const getStdout = <Trace>(
return { code, stdoutText, stderrText };
})
.mapLeft((e) => {
- trace.addTrace(LogLevel.ERROR).trace(`o.o wat ${e}`);
- return new ProcessError(`${e}`);
+ tEitherOut.trace.addTrace(LogLevel.ERROR).trace(`o.o wat ${e}`);
+ return new Error(`${e}`);
})
- .flatMap((decodedOutput): Either<ProcessError, string> => {
+ .flatMap((decodedOutput): Either<Error, string> => {
const { code, stdoutText, stderrText } = decodedOutput;
- trace.addTrace(LogLevel.DEBUG).trace(
+ tEitherOut.trace.addTrace(LogLevel.DEBUG).trace(
`stderr hehehe ${stderrText}`,
);
if (code !== 0) {
const msg =
`i weceived an exit code of ${code} i wanna zewoooo :<`;
- trace.addTrace(LogLevel.ERROR).trace(msg);
- return Either.left(new ProcessError(msg));
+ tEitherOut.trace.addTrace(LogLevel.ERROR).trace(msg);
+ return Either.left(new Error(msg));
}
return Either.right(stdoutText);
})
)
),
- ).item;
+ )
+ .get();