mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
getPortFrom should log the lines it retrived if it fails to get a port (#3395)
This commit is contained in:
parent
c3823b9d27
commit
ea4a5a4c57
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
import type { Readable } from "stream";
|
import type { Readable } from "stream";
|
||||||
import URLParse from "url-parse";
|
import URLParse from "url-parse";
|
||||||
|
import logger from "../logger";
|
||||||
|
|
||||||
interface GetPortArgs {
|
interface GetPortArgs {
|
||||||
/**
|
/**
|
||||||
@ -47,11 +48,15 @@ interface GetPortArgs {
|
|||||||
* @returns A Promise for port number
|
* @returns A Promise for port number
|
||||||
*/
|
*/
|
||||||
export function getPortFrom(stream: Readable, args: GetPortArgs): Promise<number> {
|
export function getPortFrom(stream: Readable, args: GetPortArgs): Promise<number> {
|
||||||
|
const logLines: string[] = [];
|
||||||
|
|
||||||
return new Promise<number>((resolve, reject) => {
|
return new Promise<number>((resolve, reject) => {
|
||||||
const handler = (data: any) => {
|
const handler = (data: any) => {
|
||||||
const logItem: string = data.toString();
|
const logItem: string = data.toString();
|
||||||
const match = logItem.match(args.lineRegex);
|
const match = logItem.match(args.lineRegex);
|
||||||
|
|
||||||
|
logLines.push(logItem);
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
// use unknown protocol so that there is no default port
|
// use unknown protocol so that there is no default port
|
||||||
const addr = new URLParse(`s://${match.groups.address.trim()}`);
|
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(() => {
|
const timeoutID = setTimeout(() => {
|
||||||
stream.off("data", handler);
|
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"));
|
reject(new Error("failed to retrieve port from stream"));
|
||||||
}, args.timeout ?? 5000);
|
}, args.timeout ?? 5000);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user