Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/xpc/execute_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ process.on("message", (req) => {
}
}
const request = Hub.ActionRequest.fromIPC(req);
winston.error(`Error on child: ${errorString}. WebhookID: ${request.webhookId}`);
winston.error(`Received Error on child in queue: ${errorString}. WebhookID: ${request.webhookId}`);
process.send({ success: false, message: errorString });
});
});
24 changes: 22 additions & 2 deletions lib/xpc/extended_execute_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,40 @@ process.on("message", (req) => {
let errorString;
if (err instanceof Error) {
errorString = err.message || err.toString();
if (errorString === "{}") {
winston.debug("err.message or err.toString() for Error instance resulted in '{}'. Using a more descriptive fallback.");
errorString = "Unnamed Error";
Comment on lines +26 to +28

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using a more descriptive fallback error message instead of 'Unnamed Error'. This can aid in debugging when the error object doesn't provide a clear message.

errorString = "An unspecified error occurred";

}
}
else if (typeof err === "object" && err !== null) {
try {
errorString = JSON.stringify(err);
if (Object.prototype.hasOwnProperty.call(err, "message") && typeof (err).message === "string") {
errorString = (err).message;
}
else {
const stringified = JSON.stringify(err);
if (stringified === "{}" || stringified === "[]") {
winston.debug("Error stringified into {}");
errorString = err.toString();
}
else {
errorString = stringified;
}
}
}
catch (jsonError) {
errorString = `[Object could not be stringified: ${jsonError.message || jsonError.toString()}]`;
}
}
else {
errorString = String(err);
if (errorString === "{}") {
winston.debug("String(err) resulted in '{}'. Using a generic representation for non-object error.");
errorString = "Unnamed Error";
}
}
const request = Hub.ActionRequest.fromIPC(req);
winston.error(`Error on child: ${errorString}. WebhookID: ${request.webhookId}`);
winston.error(`Received Error on child in extended queue: ${errorString}. WebhookID: ${request.webhookId}`);
process.send({ success: false, message: errorString });
});
});
2 changes: 1 addition & 1 deletion src/xpc/execute_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ process.on("message", (req) => {
}
}
const request = Hub.ActionRequest.fromIPC(req)
winston.error(`Error on child: ${errorString}. WebhookID: ${request.webhookId}`)
winston.error(`Received Error on child in queue: ${errorString}. WebhookID: ${request.webhookId}`)
process.send!({success: false, message: errorString})
})
})
24 changes: 21 additions & 3 deletions src/xpc/extended_execute_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,35 @@ process.on("message", (req) => {
let errorString
if (err instanceof Error) {
errorString = err.message || err.toString()
if (errorString === "{}") {
winston.debug("err.message or err.toString() for Error instance resulted in '{}'. Using a more descriptive fallback.")
errorString = "Unnamed Error"
Comment on lines +28 to +30

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using a more descriptive fallback error message instead of 'Unnamed Error'. This can aid in debugging when the error object doesn't provide a clear message.

errorString = "An unspecified error occurred";

}
} else if (typeof err === "object" && err !== null) {
try {
errorString = JSON.stringify(err)
if (Object.prototype.hasOwnProperty.call(err, "message") && typeof (err).message === "string") {
errorString = (err).message
} else {
const stringified = JSON.stringify(err)
if (stringified === "{}" || stringified === "[]") {
winston.debug("Error stringified into {}")
errorString = err.toString()
} else {
errorString = stringified
}
}
} catch (jsonError: any) {
errorString = `[Object could not be stringified: ${jsonError.message || jsonError.toString()}]`
}
} else {
errorString = String(err)
if (errorString === "{}") {
winston.debug("String(err) resulted in '{}'. Using a generic representation for non-object error.")
errorString = "Unnamed Error"
}
}
Comment on lines 26 to 54

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The error serialization logic is duplicated between src/xpc/extended_execute_process.ts and src/xpc/execute_process.ts. To improve maintainability and reduce redundancy, extract this logic into a shared utility function in src/hub/utils.ts and import it into both files.

// In src/hub/utils.ts
export function serializeError(err: any): string {
  let errorString: string;
  if (err instanceof Error) {
    errorString = err.message || err.toString();
    if (errorString === "{}") {
      errorString = "Unnamed Error";
    }
  } else if (typeof err === "object" && err !== null) {
    try {
      if (Object.prototype.hasOwnProperty.call(err, "message") && typeof (err).message === "string") {
        errorString = (err).message;
      } else {
        const stringified = JSON.stringify(err);
        if (stringified === "{}" || stringified === "[]") {
          errorString = err.toString();
        } else {
          errorString = stringified;
        }
      }
    } catch (jsonError: any) {
      errorString = `[Object could not be stringified: ${jsonError.message || jsonError.toString()}]`;
    }
  } else {
    errorString = String(err);
    if (errorString === "{}") {
      errorString = "Unnamed Error";
    }
  }
  return errorString;
}

// In extended_execute_process.ts and execute_process.ts
import { serializeError } from "../hub/utils";

.catch((err) => {
  const errorString = serializeError(err);
  winston.error(`Received Error on child...: ${errorString}. WebhookID: ${request.webhookId}`);
  process.send!({ success: false, message: errorString });
})

const request = Hub.ActionRequest.fromIPC(req)
winston.error(`Error on child: ${errorString}. WebhookID: ${request.webhookId}`)
winston.error(`Received Error on child in extended queue: ${errorString}. WebhookID: ${request.webhookId}`)
process.send!({success: false, message: errorString})
})
})
})