How to use the @bentley/imodeljs-common.IModelError function in @bentley/imodeljs-common

To help you get started, we’ve selected a few @bentley/imodeljs-common 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 / IModelDb.ts View on Github external
public updateModel(props: UpdateModelOptions): void {
      const jsClass = this._iModel.getJsClass(props.classFullName) as any; // "as any" so we can call the protected methods
      jsClass.onUpdate(props);

      const error = this._iModel.nativeDb.updateModel(JSON.stringify(props));
      if (error !== IModelStatus.Success)
        throw new IModelError(error, "updating model id=" + props.id, Logger.logWarning, loggerCategory);

      jsClass.onUpdated(props);
    }
github imodeljs / imodeljs / core / frontend / src / IModelConnection.ts View on Github external
// Try opening the iModel repeatedly accommodating any pending responses from the backend.
    // Waits for an increasing amount of time (but within a range) before checking on the pending request again.
    const connectionRetryIntervalRange = { min: 100, max: 5000 }; // in milliseconds
    let connectionRetryInterval = Math.min(connectionRetryIntervalRange.min, IModelConnection.connectionTimeout);

    let openForReadOperation: RpcOperation | undefined;
    let openForWriteOperation: RpcOperation | undefined;
    if (openMode === OpenMode.Readonly) {
      openForReadOperation = RpcOperation.lookup(IModelReadRpcInterface, "openForRead");
      if (!openForReadOperation)
        throw new IModelError(BentleyStatus.ERROR, "IModelReadRpcInterface.openForRead() is not available");
      openForReadOperation.policy.retryInterval = () => connectionRetryInterval;
    } else {
      openForWriteOperation = RpcOperation.lookup(IModelWriteRpcInterface, "openForWrite");
      if (!openForWriteOperation)
        throw new IModelError(BentleyStatus.ERROR, "IModelWriteRpcInterface.openForWrite() is not available");
      openForWriteOperation.policy.retryInterval = () => connectionRetryInterval;
    }

    Logger.logTrace(loggerCategory, `Received open request in IModelConnection.open`, () => iModelToken);
    Logger.logTrace(loggerCategory, `Setting retry interval in IModelConnection.open`, () => ({ ...iModelToken, connectionRetryInterval }));

    const startTime = Date.now();

    const removeListener = RpcRequest.events.addListener((type: RpcRequestEvent, request: RpcRequest) => {
      if (type !== RpcRequestEvent.PendingUpdateReceived)
        return;
      if (!(openForReadOperation && request.operation === openForReadOperation) && !(openForWriteOperation && request.operation === openForWriteOperation))
        return;

      requestContext.enter();
      Logger.logTrace(loggerCategory, "Received pending open notification in IModelConnection.open", () => iModelToken);
github imodeljs / imodeljs / core / backend / src / ECSqlStatement.ts View on Github external
return ecsqlValue.getClassNameForClassId();

        return ecsqlValue.getId();
      }
      // JS doesn't tell between int32 and larger ints, so retrieve them with the getInt64 method
      case ECSqlValueType.Int:
      case ECSqlValueType.Int64:
        return ecsqlValue.getInteger();
      case ECSqlValueType.Point2d:
        return ecsqlValue.getXAndY();
      case ECSqlValueType.Point3d:
        return ecsqlValue.getXYAndZ();
      case ECSqlValueType.String:
        return ecsqlValue.getString();
      default:
        throw new IModelError(DbResult.BE_SQLITE_ERROR, `Unsupported type ${ecsqlValue.columnInfo.getType()} of the ECSQL Value`);
    }
  }
github imodeljs / imodeljs / core / backend / src / GeometrySummary.ts View on Github external
public generateSummary(id: Id64String): string {
    let lines = ["[Geometry Summary for Element " + id + "]"];
    try {
      const geom = this.getElementGeom(id);
      if (undefined === geom)
        throw new IModelError(IModelStatus.NoGeometry, "Element is neither a geometric element nor a geometry part");

      if (undefined !== geom.geometricElement)
        lines.push(this.summarizeElement(geom.geometricElement));
      else if (undefined !== this.includePartReferences)
        lines.push(this.summarizePartReferences(id, "2d" === this.includePartReferences)); // NB: Hideously inefficient if more than one element's summary was requested.

      let curGeomParams: GeometryParams | undefined;
      let curLocalRange: Range3d | undefined;
      for (const entry of geom.iterator) {
        if (this.verboseSymbology && (undefined === curGeomParams || !curGeomParams.isEquivalent(entry.geomParams))) {
          lines.push("Symbology: " + this.stringify(entry.geomParams));
          curGeomParams = entry.geomParams.clone();
        }

        if (undefined !== entry.localRange && (undefined === curLocalRange || !curLocalRange.isAlmostEqual(entry.localRange))) {
          lines.push(this.summarizeRange3d(entry.localRange));
github imodeljs / imodeljs / core / backend / src / BriefcaseManager.ts View on Github external
private static async finishCreateBriefcase(requestContext: AuthorizedClientRequestContext, briefcase: BriefcaseEntry): Promise {
    requestContext.enter();

    try {
      // Download checkpoint
      let checkpointQuery = new CheckpointQuery().selectDownloadUrl();
      checkpointQuery = checkpointQuery.precedingCheckpoint(briefcase.targetChangeSetId);
      const checkpoints: Checkpoint[] = await BriefcaseManager.imodelClient.checkpoints.get(requestContext, briefcase.iModelId, checkpointQuery);
      requestContext.enter();
      if (checkpoints.length === 0)
        throw new IModelError(BriefcaseStatus.VersionNotFound, "Checkpoint not found", Logger.logError, loggerCategory, () => briefcase.getDebugInfo());
      const checkpoint = checkpoints[0];
      if (checkpoint.fileId)
        briefcase.fileId = checkpoint.fileId.toString();
      await BriefcaseManager.downloadCheckpoint(requestContext, checkpoint, briefcase.pathname);
      requestContext.enter();

      const perfLogger = new PerfLogger("Opening iModel - setting up context/iModel/briefcase ids", () => briefcase.getDebugInfo());
      // Setup briefcase
      // TODO: Only need to setup briefcase id for the ReadWrite case after the hub properly sets up these checkpoints
      // The following function set the briefcaseId with  sync=off which should be safe for this case. It make open faster.
      let res: DbResult = IModelHost.platform.DgnDb.unsafeSetBriefcaseId(briefcase.pathname, briefcase.briefcaseId, briefcase.iModelId, briefcase.contextId);
      if (DbResult.BE_SQLITE_OK !== res)
        throw new IModelError(res, "Unable setup briefcase id", Logger.logError, loggerCategory, () => ({ ...briefcase.getDebugInfo(), result: res }));
      perfLogger.dispose();

      // Open checkpoint
github imodeljs / imodeljs / core / backend / src / IModelDb.ts View on Github external
public closeStandalone(): void {
    if (!this.isStandalone)
      throw new IModelError(BentleyStatus.ERROR, "Cannot use to close a managed iModel. Use IModelDb.close() instead");
    BriefcaseManager.closeStandalone(this.briefcase);
    this.clearBriefcaseEntry();
  }
github imodeljs / imodeljs / core / backend / src / IModelDb.ts View on Github external
public async importSchemas(requestContext: ClientRequestContext | AuthorizedClientRequestContext, schemaFileNames: string[]): Promise {
    requestContext.enter();
    if (this.isStandalone) {
      const status = this.briefcase.nativeDb.importSchemas(schemaFileNames);
      if (DbResult.BE_SQLITE_OK !== status) {
        throw new IModelError(status, "Error importing schema", Logger.logError, loggerCategory, () => ({ schemaFileNames }));
      }
      this.clearStatementCache();
      this.clearSqliteStatementCache();
      return;
    }

    if (!(requestContext instanceof AuthorizedClientRequestContext))
      throw new IModelError(AuthStatus.Error, "Importing the schema requires an AuthorizedClientRequestContext");
    await this.concurrencyControl.lockSchema(requestContext);
    requestContext.enter();

    const stat = this.briefcase.nativeDb.importSchemas(schemaFileNames);
    if (DbResult.BE_SQLITE_OK !== stat) {
      throw new IModelError(stat, "Error importing schema", Logger.logError, loggerCategory, () => ({ schemaFileNames }));
    }
github imodeljs / imodeljs / core / backend / src / ChangedElementsDb.ts View on Github external
private _createDb(briefcase: IModelDb, pathName: string): void {
    const status: DbResult = this.nativeDb.createDb(briefcase.nativeDb, pathName);
    if (status !== DbResult.BE_SQLITE_OK)
      throw new IModelError(status, "Failed to created ECDb");
  }
github imodeljs / imodeljs / core / backend / src / BriefcaseManager.ts View on Github external
private static addPendingChangeSet(briefcase: BriefcaseEntry, changeSetId: string): void {
    const result = briefcase.nativeDb!.addPendingChangeSet(changeSetId);
    if (DbResult.BE_SQLITE_OK !== result)
      throw new IModelError(result, "Error in addPendingChangeSet", Logger.logError, loggerCategory, () => briefcase.getDebugInfo());
  }
github imodeljs / imodeljs / core / backend / src / CodeSpecs.ts View on Github external
return this._imodel.withPreparedStatement("SELECT ECInstanceId as id FROM BisCore.CodeSpec WHERE Name=?", (stmt: ECSqlStatement) => {
      stmt.bindString(1, name);
      if (DbResult.BE_SQLITE_ROW !== stmt.step())
        throw new IModelError(IModelStatus.NotFound, "CodeSpec not found", Logger.logWarning, loggingCategory, () => ({ name }));
      return Id64.fromJSON(stmt.getRow().id);
    });
  }