await callWithTelemetryAndErrorHandling()

in apps/vs-code-designer/src/app/utils/codeless/startDesignTimeApi.ts [53:147]


  await callWithTelemetryAndErrorHandling('azureLogicAppsStandard.startDesignTimeApi', async (actionContext: IActionContext) => {
    actionContext.telemetry.properties.startDesignTimeApi = 'false';

    if (!ext.designTimeInstances.has(projectPath)) {
      ext.designTimeInstances.set(projectPath, {
        port: await portfinder.getPortPromise(),
      });
    }

    const designTimeInst = ext.designTimeInstances.get(projectPath);
    const url = `http://localhost:${designTimeInst.port}${designerStartApi}`;

    if (await isDesignTimeUp(url)) {
      actionContext.telemetry.properties.isDesignTimeUp = 'true';
      const correctFuncProcess = await checkFuncProcessId(projectPath);
      if (!correctFuncProcess) {
        stopDesignTimeApi(projectPath);
        await startDesignTimeApi(projectPath);
      }
      return;
    }

    try {
      window.showInformationMessage(
        localize('azureFunctions.designTimeApi', 'Starting workflow design-time API, which might take a few seconds.'),
        'OK'
      );
      ext.outputChannel.appendLog('Starting Design Time Api');

      const designTimeDirectory: Uri | undefined = await getOrCreateDesignTimeDirectory(designTimeDirectoryName, projectPath);
      const settingsFileContent = getLocalSettingsSchema(true, projectPath);

      const hostFileContent: any = {
        version: '2.0',
        extensionBundle: {
          id: extensionBundleId,
          version: defaultVersionRange,
        },
        extensions: {
          workflow: {
            settings: {
              'Runtime.WorkflowOperationDiscoveryHostMode': 'true',
            },
          },
        },
      };

      if (designTimeDirectory) {
        await createJsonFile(designTimeDirectory, hostFileName, hostFileContent);
        await createJsonFile(designTimeDirectory, localSettingsFileName, settingsFileContent);
        await addOrUpdateLocalAppSettings(
          actionContext,
          designTimeDirectory.fsPath,
          {
            [appKindSetting]: logicAppKind,
            [ProjectDirectoryPath]: projectPath,
            [workerRuntimeKey]: WorkerRuntime.Node,
          },
          true
        );
        await updateFuncIgnore(projectPath, [`${designTimeDirectoryName}/`]);
        const cwd: string = designTimeDirectory.fsPath;
        const portArgs = `--port ${designTimeInst.port}`;
        startDesignTimeProcess(ext.outputChannel, cwd, getFunctionsCommand(), 'host', 'start', portArgs);
        await waitForDesignTimeStartUp(projectPath, url, new Date().getTime());
        ext.pinnedBundleVersion.set(projectPath, false);
        const hostfilepath: Uri = Uri.file(path.join(cwd, hostFileName));
        const data = JSON.parse(fs.readFileSync(hostfilepath.fsPath, 'utf-8'));
        if (data.extensionBundle) {
          const versionWithoutSpaces = data.extensionBundle.version.replace(/\s+/g, '');
          const rangeWithoutSpaces = defaultVersionRange.replace(/\s+/g, '');
          if (data.extensionBundle.id === extensionBundleId && versionWithoutSpaces === rangeWithoutSpaces) {
            ext.currentBundleVersion.set(projectPath, ext.latestBundleVersion);
          } else if (data.extensionBundle.id === extensionBundleId && versionWithoutSpaces !== rangeWithoutSpaces) {
            ext.currentBundleVersion.set(projectPath, extractPinnedVersion(data.extensionBundle.version) ?? data.extensionBundle.version);
            ext.pinnedBundleVersion.set(projectPath, true);
          }
        }
        actionContext.telemetry.properties.startDesignTimeApi = 'true';
      } else {
        throw new Error(localize('DesignTimeDirectoryError', 'Failed to create design-time directory.'));
      }
    } catch (error) {
      const errorMessage = error instanceof Error ? error.message : error;
      const viewOutput: MessageItem = { title: localize('viewOutput', 'View output') };
      const message = localize('DesignTimeError', "Can't start the background design-time process.") + errorMessage;
      actionContext.telemetry.properties.startDesignTimeApiError = errorMessage;

      window.showErrorMessage(message, viewOutput).then(async (result) => {
        if (result === viewOutput) {
          ext.outputChannel.show();
        }
      });
    }
  });