From d54e91c6582ed160cf2f2fcf977e48b4439d133b Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Sun, 18 May 2025 22:54:15 -0700 Subject: snapshot --- u/process/run.ts | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'u/process/run.ts') 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 = ( c: ITraceable, options: Deno.CommandOptions = {}, -): Promise> => +): Promise> => 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 = ( ...options, }).output(); }) - .map(({ item: p }) => - Either.fromFailableAsync(p) + .map((tOut) => + Either.fromFailableAsync(tOut.get()) ) .map( - TraceUtil.promiseify(({ item: eitherOutput, trace }) => - eitherOutput.flatMap(({ code, stderr, stdout }) => + TraceUtil.promiseify((tEitherOut) => + tEitherOut.get().flatMap(({ code, stderr, stdout }) => Either .fromFailable(() => { const stdoutText = new TextDecoder().decode(stdout); @@ -42,22 +42,23 @@ export const getStdout = ( 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 => { + .flatMap((decodedOutput): Either => { 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(); -- cgit v1.2.3-70-g09d2