getPortFrom should log the lines it retrived if it fails to get a port (#3395)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-07-15 14:19:33 -04:00
1 parent c3823b9d27
commit ea4a5a4c57
1 file changed
+6
+6
View File
@@ -21,6 +21,7 @@
import type { Readable } from "stream";
import URLParse from "url-parse";
import logger from "../logger";
interface GetPortArgs {
/**
@@ -47,11 +48,15 @@ interface GetPortArgs {
* @returns A Promise for port number
*/
export function getPortFrom(stream: Readable, args: GetPortArgs): Promise<number> {
const logLines: string[] = [];
return new Promise<number>((resolve, reject) => {
const handler = (data: any) => {
const logItem: string = data.toString();
const match = logItem.match(args.lineRegex);
logLines.push(logItem);
if (match) {
// use unknown protocol so that there is no default port
const addr = new URLParse(`s://${match.groups.address.trim()}`);
@@ -64,6 +69,7 @@ export function getPortFrom(stream: Readable, args: GetPortArgs): Promise<number
};
const timeoutID = setTimeout(() => {
stream.off("data", handler);
logger.warn(`[getPortFrom]: failed to retrieve port via ${args.lineRegex.toString()}: ${logLines}`);
reject(new Error("failed to retrieve port from stream"));
}, args.timeout ?? 5000);