Skip to content

Commit

Permalink
maker-appimage: Pass mksquashfs stderr on close.
Browse files Browse the repository at this point in the history
This tries to implement passing the logs when the exception is thrown.
  • Loading branch information
SpacingBat3 committed Jan 23, 2024
1 parent 130becb commit 85f474b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
5 changes: 4 additions & 1 deletion makers/appimage/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,10 @@ export default class MakerAppImage<C extends MakerAppImageConfig> extends MakerB
await new Promise((resolve, reject) => {
mkdir(dirname(outFile), {recursive: true}).then(() => {
mkSquashFs(...mkSquashFsArgs)
.once("close", (code) => code !== 0 ? reject(new Error(`mksquashfs returned non-zero code: '${code}'`)) : resolve(undefined))
.once("close", (code,_signal,msg) => code !== 0 ?
reject(new Error(`mksquashfs returned ${msg ? `'${msg}' in stderr` : "non-zero code"} (${code}).`)):
resolve(undefined)
)
.once("error", (error) => reject(error));
}).catch(error => reject(error));
});
Expand Down
28 changes: 25 additions & 3 deletions makers/appimage/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ interface mkSqFSListenerArgs {
/** A returned code when process normally exits. */
code: number|null,
/** A signal which closed the process. */
signal:NodeJS.Signals|null
signal:NodeJS.Signals|null,
/** A message printed to STDERR, if available. */
msg?:string
];
progress: [
/** A number from range 0-100 indicating the current progress made on creating the image. */
Expand Down Expand Up @@ -191,7 +193,23 @@ export function mkSquashFs(...squashfsOptions:string[]) {
}
});
let lastProgress = 0;
mkSquashFS.on("message", (chunk) => {
let stderrCollector = "";
mkSquashFS.stderr?.on("data", (chunk:unknown) => {
switch(true) {
//@ts-expect-error falls through
case chunk instanceof ArrayBuffer:
chunk = Buffer.from(chunk);
//@ts-expect-error falls through
case chunk instanceof Buffer:
chunk = (chunk as Buffer).toString();
case chunk instanceof String:
stderrCollector+=(chunk as string);
break;
default:
throw new TypeError("Unresolved chunk type.")
}
})
mkSquashFS.stdout?.on("data", (chunk) => {
const message = chunk.toString();
const progress = message.match(/\] [0-9/]+ ([0-9]+)%/)?.[1];
if(progress !== undefined) {
Expand All @@ -201,7 +219,11 @@ export function mkSquashFs(...squashfsOptions:string[]) {
lastProgress = progInt;
}
});
mkSquashFS.on("close", (...args) => event.emit("close",...args));
mkSquashFS.on("close", (...args) => mkSquashFS.emit(
"close",
...args,
stderrCollector === "" ? undefined : stderrCollector
));
mkSquashFS.on("error", (error) => event.emit("error", error));
});
return event;
Expand Down

0 comments on commit 85f474b

Please sign in to comment.