await callWithTelemetryAndErrorHandling()

in src/debugging/DockerServerReadyAction.ts [57:124]


        await callWithTelemetryAndErrorHandling('dockerServerReadyAction.serverReadyDetector.openExternalWithString', async (context: IActionContext) => {
            // Don't actually telemetrize or show anything (same as prior behavior), but wrap call to get an IActionContext
            context.telemetry.suppressAll = true;
            context.errorHandling.suppressDisplay = true;
            context.errorHandling.rethrow = false;

            if (captureString === '') {
                // nothing captured by reg exp -> use the uriFormat as the target url without substitution
                // verify that format does not contain '%s'
                if (format.indexOf('%s') >= 0) {
                    const errMsg = localize('vscode-docker.debug.serverReady.noCapture', 'Format uri (\'{0}\') uses a substitution placeholder but pattern did not capture anything.', format);
                    void vscode.window.showErrorMessage(errMsg, { modal: true });
                    return;
                }
                captureString = format;
            } else if (/^[0-9]+$/.test(captureString)) {
                // looks like a port number -> use the uriFormat and substitute a single "%s" with the port
                // verify that format only contains a single '%s'
                const s = format.split('%s');
                if (s.length !== 2) {
                    const errMsg = localize('vscode-docker.debug.serverReady.oneSubstitution', 'Format uri (\'{0}\') must contain exactly one substitution placeholder.', format);
                    void vscode.window.showErrorMessage(errMsg, { modal: true });
                    return;
                }

                const containerPort = Number.parseInt(captureString, 10);
                const containerInspectInfo = await ext.dockerClient.inspectContainer(context, args.containerName);
                const hostPort = containerInspectInfo.NetworkSettings.Ports[`${containerPort}/tcp`][0].HostPort;

                if (!hostPort) {
                    throw new Error(localize('vscode-docker.debug.serverReady.noHostPortA', 'Could not determine host port mapped to container port {0} in container \'{1}\'.', containerPort, args.containerName));
                }

                captureString = util.format(format, hostPort);
            } else {
                const containerPort = this.getContainerPort(captureString);

                if (containerPort === undefined) {
                    const errMsg = localize('vscode-docker.debug.serverReady.noCapturedPort', 'Captured string (\'{0}\') must contain a port number.', captureString);
                    void vscode.window.showErrorMessage(errMsg, { modal: true });
                    return;
                }

                const containerProtocol = this.getContainerProtocol(captureString);
                const containerInspectInfo = await ext.dockerClient.inspectContainer(context, args.containerName);
                const hostPort = containerInspectInfo.NetworkSettings.Ports[`${containerPort}/tcp`][0].HostPort;

                if (!hostPort) {
                    throw new Error(localize('vscode-docker.debug.serverReady.noHostPortB', 'Could not determine host port mapped to container port {0} in container \'{1}\'.', containerPort, args.containerName));
                }

                const s = format.split('%s');

                if (s.length === 1) {
                    // Format string has no substitutions, so use as-is...
                    captureString = format;
                } else if (s.length === 3) {
                    // There are exactly two substitutions (which is expected)...
                    captureString = util.format(format, containerProtocol, hostPort);
                } else {
                    const errMsg = localize('vscode-docker.debug.serverReady.twoSubstitutions', 'Format uri (\'{0}\') must contain exactly two substitution placeholders.', format);
                    void vscode.window.showErrorMessage(errMsg, { modal: true });
                    return;
                }
            }

            this.openExternalWithUri(session, captureString);
        });