@itwin/core-i18n 5.7.0-dev.14 → 5.7.0-dev.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21352,30 +21352,58 @@ class Logger {
21352
21352
  const minLevel = Logger.getLevel(category);
21353
21353
  return (minLevel !== undefined) && (level >= minLevel);
21354
21354
  }
21355
- /** Log the specified message to the **error** stream.
21356
- * @param category The category of the message.
21357
- * @param message The message.
21358
- * @param metaData Optional data for the message
21359
- */
21360
- static logError(category, message, metaData) {
21361
- if (Logger._logError && Logger.isEnabled(category, LogLevel.Error))
21362
- Logger._logError(category, message, metaData);
21355
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
21356
+ static logError(category, messageOrError, metaData) {
21357
+ if (Logger._logError && Logger.isEnabled(category, LogLevel.Error)) {
21358
+ if (typeof messageOrError === "string") {
21359
+ Logger._logError(category, messageOrError, metaData);
21360
+ }
21361
+ else if (_BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.isError(messageOrError)) {
21362
+ // For backwards compatibility, log BentleyError old way
21363
+ Logger._logError(category, Logger.getExceptionMessage(messageOrError), () => ({ ..._BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getErrorMetadata(messageOrError), exceptionType: messageOrError?.constructor?.name ?? "<Unknown>", ..._BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getMetaData(metaData) }));
21364
+ }
21365
+ else {
21366
+ // Else, return a copy of the error, with non-enumerable members `message` and `stack` removed, as "metadata" for log.
21367
+ Logger._logError(category, Logger.getExceptionMessage(messageOrError), Logger.getExceptionMetaData(messageOrError, metaData));
21368
+ }
21369
+ }
21363
21370
  }
21364
- static getExceptionMessage(err) {
21365
- if (err === undefined) {
21366
- return "Error: err is undefined.";
21371
+ /**
21372
+ * Get a sting message for a given error.
21373
+ * For legacy [[BentleyError]] exceptions, this will include the error message and, optionally, the call stack.
21374
+ * For other exceptions, this will include the stringified version of the error.
21375
+ * @param error The error to get the message for
21376
+ * @returns A string message for the error
21377
+ */
21378
+ static getExceptionMessage(error) {
21379
+ if (error === undefined) {
21380
+ return "Error: error is undefined.";
21381
+ }
21382
+ if (error === null) {
21383
+ return "Error: error is null.";
21367
21384
  }
21368
- if (err === null) {
21369
- return "Error: err is null.";
21385
+ const stack = Logger.logExceptionCallstacks ? `\n${_BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getErrorStack(error)}` : "";
21386
+ return _BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getErrorMessage(error) + stack;
21387
+ }
21388
+ /**
21389
+ * Merged passed metaData with error properties into one LoggingMetaData, with the passed metaData taking precedence in case of conflict.
21390
+ * @param error The error to be logged as metadata
21391
+ * @param metaData Optional metadata to be merged with the error
21392
+ * @returns A function returning the merged metadata
21393
+ */
21394
+ static getExceptionMetaData(error, metaData) {
21395
+ const exceptionType = error?.constructor?.name ?? "<Unknown>";
21396
+ if (metaData === undefined) {
21397
+ return () => ({ exceptionType, ...error });
21370
21398
  }
21371
- const stack = Logger.logExceptionCallstacks ? `\n${_BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getErrorStack(err)}` : "";
21372
- return _BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getErrorMessage(err) + stack;
21399
+ return () => ({ exceptionType, ...error, ..._BentleyError__WEBPACK_IMPORTED_MODULE_1__.BentleyError.getMetaData(metaData) });
21373
21400
  }
21374
21401
  /** Log the specified exception.
21375
21402
  * For legacy [[BentleyError]] exceptions, the special "exceptionType" property will be added as metadata. Otherwise, all enumerable members of the exception are logged as metadata.
21376
21403
  * @param category The category of the message.
21377
21404
  * @param err The exception object.
21378
21405
  * @param log The logger output function to use - defaults to Logger.logError
21406
+ * @deprecated in 5.6. Use logError(category, error, metaData) instead, which will log exceptions in the same way but is more flexible and easier to use.
21379
21407
  */
21380
21408
  static logException(category, err, log = (_category, message, metaData) => Logger.logError(_category, message, metaData)) {
21381
21409
  log(category, Logger.getExceptionMessage(err), () => {
@@ -21661,11 +21689,15 @@ class OneAtATimeAction {
21661
21689
  return await promise;
21662
21690
  }
21663
21691
  finally {
21664
- // do all of this whether promise was fulfilled or rejected
21665
- this._active = this._pending; // see if there's a pending request waiting
21666
- this._pending = undefined; // clear pending
21667
- if (this._active)
21668
- this._active.start(); // eslint-disable-line @typescript-eslint/no-floating-promises
21692
+ // A replaced pending request can be abandoned before it ever becomes active.
21693
+ // Only the currently active entry is allowed to promote/start the next pending request.
21694
+ if (this._active === entry) {
21695
+ // do all of this whether promise was fulfilled or rejected
21696
+ this._active = this._pending; // see if there's a pending request waiting
21697
+ this._pending = undefined; // clear pending
21698
+ if (this._active)
21699
+ this._active.start(); // eslint-disable-line @typescript-eslint/no-floating-promises
21700
+ }
21669
21701
  }
21670
21702
  }
21671
21703
  }
@@ -23748,7 +23780,7 @@ class UnexpectedErrors {
23748
23780
  /** handler for logging exception to console */
23749
23781
  static consoleLog = (e) => console.error(e); // eslint-disable-line no-console
23750
23782
  /** handler for logging exception with [[Logger]] */
23751
- static errorLog = (e) => _Logger__WEBPACK_IMPORTED_MODULE_0__.Logger.logException("unhandled", e);
23783
+ static errorLog = (e) => _Logger__WEBPACK_IMPORTED_MODULE_0__.Logger.logError("unhandled", e);
23752
23784
  static _telemetry = [];
23753
23785
  static _handler = this.errorLog; // default to error logging
23754
23786
  constructor() { } // this is a singleton