How to use the @bentley/bentleyjs-core.Logger.logError function in @bentley/bentleyjs-core

To help you get started, we’ve selected a few @bentley/bentleyjs-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imodeljs / imodeljs / core / backend / src / BriefcaseManager.ts View on Github external
// Validate the briefcase
    let isValidBriefcase: boolean = true;
    if (briefcase.currentChangeSetId !== briefcase.targetChangeSetId) {
      if (openParams.syncMode === SyncMode.FixedVersion) {
        Logger.logError(loggerCategory, "Briefcase found is invalid (is not of required version). Deleting it to allow retries", () => briefcase.getDebugInfo());
        isValidBriefcase = false;
      } else {
        if (nativeDb.hasUnsavedChanges() || nativeDb.hasSavedChanges())
          Logger.logWarning(loggerCategory, "Briefcase found with local changes, but is not of required version. Ignoring required version", () => briefcase.getDebugInfo());
        else
          isValidBriefcase = false; // Invalidate the briefcase to refetch it
      }
    }
    if (briefcase.briefcaseId !== briefcaseId) {
      Logger.logError(loggerCategory, "Briefcase found is invalid (does not have the expected briefcase id). Deleting it to allow retries", () => ({ expectedBriefcaseId: briefcaseId, ...briefcase.getDebugInfo() }));
      isValidBriefcase = false;
    }
    if (!isValidBriefcase) {
      BriefcaseManager.closeBriefcase(briefcase, false);
      BriefcaseManager.deleteBriefcaseFromLocalDisk(briefcase);
      return undefined;
    }

    const cachedBriefcase = this._cache.findBriefcase(briefcase);
    if (cachedBriefcase) {
      // TODO: Turn this into an assertion, after ensuring this doesn't happen in deployments
      Logger.logError(loggerCategory, "Attempting to open and/or create briefcase twice", () => briefcase.getDebugInfo());
      return cachedBriefcase;
    }
    BriefcaseManager._cache.addBriefcase(briefcase);
    briefcase.isPending = this.finishOpenBriefcase(requestContext, briefcase);
github imodeljs / imodeljs / core / markup / src / Markup.ts View on Github external
}

      // is the source view too wide? If so, we need to scale the image down.
      if (canvas.width > result.maxWidth) {
        // yes, we have to scale it down, create a new canvas and set the new canvas' size
        const newCanvas = document.createElement("canvas");
        newCanvas.width = result.maxWidth;
        newCanvas.height = canvas.height * (result.maxWidth / canvas.width);
        newCanvas.getContext("2d")!.drawImage(canvas, 0, 0, canvas.width, canvas.height, 0, 0, newCanvas.width, newCanvas.height);
        canvas = newCanvas; // return the image from adjusted canvas, not view canvas.
      }

      // return the markup data to be saved by the application.
      image = (!result.imageFormat ? undefined : canvas.toDataURL(result.imageFormat));
    } catch (e) {
      Logger.logError(FrontendLoggerCategory.Package + ".markup", "Error creating image from svg", () => ({ message: e.message }));
    }
    return { rect: { width: canvas.width, height: canvas.height }, svg, image };
  }
github imodeljs / imodeljs / ui / framework / src / ui-framework / pickers / ViewSelector.tsx View on Github external
private _setEnabled = async (item: ListItem, _enabled: boolean) => {
    const activeContentControl = ContentViewManager.getActiveContentControl() as unknown as SupportsViewSelectorChange;
    if (!activeContentControl || !activeContentControl.supportsViewSelectorChange) {
      Logger.logError(UiFramework.loggerCategory(this), `No active ContentControl for ViewSelector change`);
      return;
    }

    // Enable the item temporarily to let user see that their click was registered
    // while we query for view state and change the current view which may take a bit
    if (_enabled && item.type !== ListItemType.Container) {
      // This itemMapper simply looks through all the list items and their nested children and enables the one
      // that we have registered to enable
      // Also disable all other items
      let itemMapper: (tempItem: ListItem) => ListItem;
      itemMapper = (tempItem: ListItem) => {
        if (tempItem.type === ListItemType.Container) {
          return { ...tempItem, children: tempItem.children!.map(itemMapper) };
        } else if (tempItem.key === item.key) {
          return { ...tempItem, enabled: true };
        } else {
github imodeljs / imodeljs / core / backend / src / BriefcaseManager.ts View on Github external
}
    }
    if (briefcase.briefcaseId !== briefcaseId) {
      Logger.logError(loggerCategory, "Briefcase found is invalid (does not have the expected briefcase id). Deleting it to allow retries", () => ({ expectedBriefcaseId: briefcaseId, ...briefcase.getDebugInfo() }));
      isValidBriefcase = false;
    }
    if (!isValidBriefcase) {
      BriefcaseManager.closeBriefcase(briefcase, false);
      BriefcaseManager.deleteBriefcaseFromLocalDisk(briefcase);
      return undefined;
    }

    const cachedBriefcase = this._cache.findBriefcase(briefcase);
    if (cachedBriefcase) {
      // TODO: Turn this into an assertion, after ensuring this doesn't happen in deployments
      Logger.logError(loggerCategory, "Attempting to open and/or create briefcase twice", () => briefcase.getDebugInfo());
      return cachedBriefcase;
    }
    BriefcaseManager._cache.addBriefcase(briefcase);
    briefcase.isPending = this.finishOpenBriefcase(requestContext, briefcase);
    return briefcase;
  }
github imodeljs / imodeljs / core / backend / src / PromiseMemoizer.ts View on Github external
public memoize = (...args: any[]): QueryablePromise => {
    const key: string = this._generateKeyFn(...args);
    let qp: QueryablePromise | undefined = this._cachedPromises.get(key);
    if (qp)
      return qp;

    if (this._cachedPromises.size >= this._maxCacheSize) {
      this._purgeResolvedEntries();
      if (this._cachedPromises.size >= this._maxCacheSize) {
        Logger.logError(BackendLoggerCategory.PromiseMemoizer, "Cleared too many unresolved entries in memoizer cache");
        this.clearCache();
      }
    }

    const p = this._memoizeFn(...args);
    qp = new QueryablePromise(p);
    this._cachedPromises.set(key, qp);
    return qp;
  }
github imodeljs / imodeljs / core / clients / src / ECJsonTypeMap.ts View on Github external
public static fromJson(typedConstructor: new () => T, applicationKey: string, ecJsonInstance: any): T | undefined {
    const mappedClassEntry: ClassEntry | undefined = ECJsonTypeMap.getClassByType(typedConstructor);
    if (!mappedClassEntry) {
      Logger.logError(loggerCategory, `Type ${typedConstructor.name} is not mapped to an ECClass. Supply the appropriate class decorator`);
      return undefined;
    }

    const lowCaseApplicationKey = applicationKey.toLowerCase();
    const mappedApplicationEntry: ApplicationEntry | undefined = mappedClassEntry.getApplicationByKey(lowCaseApplicationKey);
    if (!mappedApplicationEntry) {
      Logger.logError(loggerCategory, `Type ${typedConstructor.name} is not mapped for the supplied application.`);
      return undefined;
    }

    let ecJsonClassKey: string;
    if (mappedApplicationEntry.classKeyMapInfo.classKeyPropertyName)
      ecJsonClassKey = ecJsonInstance[mappedApplicationEntry.classKeyMapInfo.classKeyPropertyName];
    else if (mappedApplicationEntry.classKeyMapInfo.schemaPropertyName && mappedApplicationEntry.classKeyMapInfo.classPropertyName)
      ecJsonClassKey = ecJsonInstance[mappedApplicationEntry.classKeyMapInfo.schemaPropertyName] + "." + ecJsonInstance[mappedApplicationEntry.classKeyMapInfo.classPropertyName];
    else {
      assert(false, "Unexpected classKeyMapInfo");
      return undefined;
    }

    if (mappedApplicationEntry.classKey !== ecJsonClassKey) {
      Logger.logError(loggerCategory, `The ClassKey ${mappedApplicationEntry.classKey} was specified to map with ${typedConstructor.name}, but does not match that specified in the JSON: ${ecJsonClassKey} `);
      return undefined;
github imodeljs / imodeljs / core / backend / src / BriefcaseManager.ts View on Github external
const curPath = path.join(folderPath, file);
        if (IModelJsFs.lstatSync(curPath)!.isDirectory) {
          BriefcaseManager.deleteFolderRecursive(curPath);
        } else {
          try {
            IModelJsFs.unlinkSync(curPath);
          } catch (error) {
            Logger.logError(loggerCategory, `Cannot delete file ${curPath}`);
            throw error;
          }
        }
      }
      try {
        IModelJsFs.rmdirSync(folderPath);
      } catch (error) {
        Logger.logError(loggerCategory, `Cannot delete folder: ${folderPath}`);
        throw error;
      }
    } catch (error) {
    }

    return !IModelJsFs.existsSync(folderPath);
  }
github imodeljs / imodeljs / core / frontend / src / IModelApp.ts View on Github external
public static registerEntityState(classFullName: string, classType: typeof EntityState) {
    const lowerName = classFullName.toLowerCase();
    if (this._entityClasses.has(lowerName)) {
      const errMsg = "Class " + classFullName + " is already registered. Make sure static schemaName and className members are correct on class " + classType.name;
      Logger.logError(FrontendLoggerCategory.IModelConnection, errMsg);
      throw new Error(errMsg);
    }

    this._entityClasses.set(lowerName, classType);
  }
github imodeljs / imodeljs / ui / framework / src / ui-framework / content / ContentGroup.tsx View on Github external
public getControlFromElement(node: React.ReactNode): ContentControl | undefined {
    if (this._contentSetMap.size === 0)
      this.getContentNodes();

    if (node && (node as React.ReactElement).key)
      return this._contentSetMap.get((node as React.ReactElement).key as string);

    Logger.logError(UiFramework.loggerCategory(this), `getControlFromElement: no control found for element`);
    return undefined;
  }