@fluidframework/telemetry-utils 2.0.0-internal.6.1.1 → 2.0.0-internal.6.2.0

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.
Files changed (109) hide show
  1. package/.eslintrc.js +2 -1
  2. package/CHANGELOG.md +31 -0
  3. package/README.md +4 -3
  4. package/dist/config.d.ts.map +1 -1
  5. package/dist/config.js +9 -4
  6. package/dist/config.js.map +1 -1
  7. package/dist/error.d.ts +92 -0
  8. package/dist/error.d.ts.map +1 -0
  9. package/dist/error.js +133 -0
  10. package/dist/error.js.map +1 -0
  11. package/dist/errorLogging.d.ts +27 -11
  12. package/dist/errorLogging.d.ts.map +1 -1
  13. package/dist/errorLogging.js +42 -17
  14. package/dist/errorLogging.js.map +1 -1
  15. package/dist/eventEmitterWithErrorHandling.d.ts +2 -2
  16. package/dist/eventEmitterWithErrorHandling.d.ts.map +1 -1
  17. package/dist/eventEmitterWithErrorHandling.js +4 -1
  18. package/dist/eventEmitterWithErrorHandling.js.map +1 -1
  19. package/dist/events.d.ts +1 -1
  20. package/dist/events.d.ts.map +1 -1
  21. package/dist/events.js.map +1 -1
  22. package/dist/fluidErrorBase.d.ts +48 -15
  23. package/dist/fluidErrorBase.d.ts.map +1 -1
  24. package/dist/fluidErrorBase.js +18 -11
  25. package/dist/fluidErrorBase.js.map +1 -1
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +7 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/logger.d.ts +28 -16
  31. package/dist/logger.d.ts.map +1 -1
  32. package/dist/logger.js +41 -14
  33. package/dist/logger.js.map +1 -1
  34. package/dist/mockLogger.d.ts +14 -5
  35. package/dist/mockLogger.d.ts.map +1 -1
  36. package/dist/mockLogger.js +19 -7
  37. package/dist/mockLogger.js.map +1 -1
  38. package/dist/sampledTelemetryHelper.d.ts +8 -7
  39. package/dist/sampledTelemetryHelper.d.ts.map +1 -1
  40. package/dist/sampledTelemetryHelper.js +10 -8
  41. package/dist/sampledTelemetryHelper.js.map +1 -1
  42. package/dist/telemetryTypes.d.ts +8 -4
  43. package/dist/telemetryTypes.d.ts.map +1 -1
  44. package/dist/telemetryTypes.js.map +1 -1
  45. package/dist/thresholdCounter.d.ts.map +1 -1
  46. package/dist/thresholdCounter.js.map +1 -1
  47. package/dist/utils.d.ts +1 -1
  48. package/dist/utils.d.ts.map +1 -1
  49. package/dist/utils.js.map +1 -1
  50. package/lib/config.d.ts.map +1 -1
  51. package/lib/config.js +9 -4
  52. package/lib/config.js.map +1 -1
  53. package/lib/error.d.ts +92 -0
  54. package/lib/error.d.ts.map +1 -0
  55. package/lib/error.js +125 -0
  56. package/lib/error.js.map +1 -0
  57. package/lib/errorLogging.d.ts +27 -11
  58. package/lib/errorLogging.d.ts.map +1 -1
  59. package/lib/errorLogging.js +42 -17
  60. package/lib/errorLogging.js.map +1 -1
  61. package/lib/eventEmitterWithErrorHandling.d.ts +2 -2
  62. package/lib/eventEmitterWithErrorHandling.d.ts.map +1 -1
  63. package/lib/eventEmitterWithErrorHandling.js +4 -1
  64. package/lib/eventEmitterWithErrorHandling.js.map +1 -1
  65. package/lib/events.d.ts +1 -1
  66. package/lib/events.d.ts.map +1 -1
  67. package/lib/events.js.map +1 -1
  68. package/lib/fluidErrorBase.d.ts +48 -15
  69. package/lib/fluidErrorBase.d.ts.map +1 -1
  70. package/lib/fluidErrorBase.js +18 -11
  71. package/lib/fluidErrorBase.js.map +1 -1
  72. package/lib/index.d.ts +1 -0
  73. package/lib/index.d.ts.map +1 -1
  74. package/lib/index.js +1 -0
  75. package/lib/index.js.map +1 -1
  76. package/lib/logger.d.ts +28 -16
  77. package/lib/logger.d.ts.map +1 -1
  78. package/lib/logger.js +41 -14
  79. package/lib/logger.js.map +1 -1
  80. package/lib/mockLogger.d.ts +14 -5
  81. package/lib/mockLogger.d.ts.map +1 -1
  82. package/lib/mockLogger.js +19 -7
  83. package/lib/mockLogger.js.map +1 -1
  84. package/lib/sampledTelemetryHelper.d.ts +8 -7
  85. package/lib/sampledTelemetryHelper.d.ts.map +1 -1
  86. package/lib/sampledTelemetryHelper.js +10 -8
  87. package/lib/sampledTelemetryHelper.js.map +1 -1
  88. package/lib/telemetryTypes.d.ts +8 -4
  89. package/lib/telemetryTypes.d.ts.map +1 -1
  90. package/lib/telemetryTypes.js.map +1 -1
  91. package/lib/thresholdCounter.d.ts.map +1 -1
  92. package/lib/thresholdCounter.js.map +1 -1
  93. package/lib/utils.d.ts +1 -1
  94. package/lib/utils.d.ts.map +1 -1
  95. package/lib/utils.js.map +1 -1
  96. package/package.json +12 -12
  97. package/src/config.ts +12 -7
  98. package/src/error.ts +202 -0
  99. package/src/errorLogging.ts +78 -38
  100. package/src/eventEmitterWithErrorHandling.ts +4 -2
  101. package/src/events.ts +3 -3
  102. package/src/fluidErrorBase.ts +62 -26
  103. package/src/index.ts +7 -0
  104. package/src/logger.ts +109 -35
  105. package/src/mockLogger.ts +25 -14
  106. package/src/sampledTelemetryHelper.ts +17 -13
  107. package/src/telemetryTypes.ts +20 -4
  108. package/src/thresholdCounter.ts +2 -2
  109. package/src/utils.ts +1 -1
package/lib/error.js ADDED
@@ -0,0 +1,125 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { FluidErrorTypes, } from "@fluidframework/core-interfaces";
6
+ import { LoggingError, NORMALIZED_ERROR_TYPE, isExternalError, normalizeError, wrapError, } from "./errorLogging";
7
+ /**
8
+ * Generic wrapper for an unrecognized/uncategorized error object
9
+ */
10
+ export class GenericError extends LoggingError {
11
+ /**
12
+ * Create a new GenericError
13
+ * @param message - Error message
14
+ * @param error - inner error object
15
+ * @param props - Telemetry props to include when the error is logged
16
+ */
17
+ // TODO: Use `unknown` instead (API breaking change because error is not just an input parameter, but a public member of the class)
18
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
19
+ constructor(message, error, props) {
20
+ // Don't try to log the inner error
21
+ super(message, props, new Set(["error"]));
22
+ this.error = error;
23
+ this.errorType = FluidErrorTypes.genericError;
24
+ }
25
+ }
26
+ /**
27
+ * Error indicating an API is being used improperly resulting in an invalid operation.
28
+ */
29
+ export class UsageError extends LoggingError {
30
+ constructor(message, props) {
31
+ super(message, { ...props, usageError: true });
32
+ this.errorType = FluidErrorTypes.usageError;
33
+ }
34
+ }
35
+ /**
36
+ * DataCorruptionError indicates that we encountered definitive evidence that the data at rest
37
+ * backing this container is corrupted, and this container would never be expected to load properly again
38
+ */
39
+ export class DataCorruptionError extends LoggingError {
40
+ constructor(message, props) {
41
+ super(message, { ...props, dataProcessingError: 1 });
42
+ this.errorType = FluidErrorTypes.dataCorruptionError;
43
+ this.canRetry = false;
44
+ }
45
+ }
46
+ /**
47
+ * Indicates we hit a fatal error while processing incoming data from the Fluid Service.
48
+ *
49
+ * @remarks
50
+ *
51
+ * The error will often originate in the dataStore or DDS implementation that is responding to incoming changes.
52
+ * This differs from {@link DataCorruptionError} in that this may be a transient error that will not repro in another
53
+ * client or session.
54
+ */
55
+ export class DataProcessingError extends LoggingError {
56
+ constructor(errorMessage) {
57
+ super(errorMessage);
58
+ /**
59
+ * {@inheritDoc IFluidErrorBase.errorType}
60
+ */
61
+ this.errorType = FluidErrorTypes.dataProcessingError;
62
+ this.canRetry = false;
63
+ }
64
+ /**
65
+ * Create a new `DataProcessingError` detected and raised within the Fluid Framework.
66
+ */
67
+ static create(errorMessage, dataProcessingCodepath, sequencedMessage, props = {}) {
68
+ const dataProcessingError = DataProcessingError.wrapIfUnrecognized(errorMessage, dataProcessingCodepath, sequencedMessage);
69
+ dataProcessingError.addTelemetryProperties(props);
70
+ return dataProcessingError;
71
+ }
72
+ /**
73
+ * Wrap the given error in a `DataProcessingError`, unless the error is already of a known type
74
+ * with the exception of a normalized {@link LoggingError}, which will still be wrapped.
75
+ *
76
+ * In either case, the error will have some relevant properties added for telemetry.
77
+ *
78
+ * @remarks
79
+ *
80
+ * We wrap conditionally since known error types represent well-understood failure modes, and ideally
81
+ * one day we will move away from throwing these errors but rather we'll return them.
82
+ * But an unrecognized error needs to be classified as `DataProcessingError`.
83
+ *
84
+ * @param originalError - The error to be converted.
85
+ * @param dataProcessingCodepath - Which code-path failed while processing data.
86
+ * @param messageLike - Message to include info about via telemetry props.
87
+ *
88
+ * @returns Either a new `DataProcessingError`, or (if wrapping is deemed unnecessary) the given error.
89
+ */
90
+ static wrapIfUnrecognized(originalError, dataProcessingCodepath, messageLike) {
91
+ const props = {
92
+ dataProcessingError: 1,
93
+ dataProcessingCodepath,
94
+ ...(messageLike === undefined
95
+ ? undefined
96
+ : extractSafePropertiesFromMessage(messageLike)),
97
+ };
98
+ const normalizedError = normalizeError(originalError, { props });
99
+ // Note that other errors may have the NORMALIZED_ERROR_TYPE errorType,
100
+ // but if so they are still suitable to be wrapped as DataProcessingError.
101
+ if (isExternalError(normalizedError) ||
102
+ normalizedError.errorType === NORMALIZED_ERROR_TYPE) {
103
+ // Create a new DataProcessingError to wrap this external error
104
+ const dataProcessingError = wrapError(normalizedError, (message) => new DataProcessingError(message));
105
+ // Copy over the props above and any others added to this error since first being normalized
106
+ dataProcessingError.addTelemetryProperties(normalizedError.getTelemetryProperties());
107
+ return dataProcessingError;
108
+ }
109
+ return normalizedError;
110
+ }
111
+ }
112
+ /**
113
+ * Extracts specific properties from the provided message that we know are safe to log.
114
+ *
115
+ * @param messageLike - Message to include info about via telemetry props.
116
+ */
117
+ export const extractSafePropertiesFromMessage = (messageLike) => ({
118
+ messageClientId: messageLike.clientId === null ? "null" : messageLike.clientId,
119
+ messageSequenceNumber: messageLike.sequenceNumber,
120
+ messageClientSequenceNumber: messageLike.clientSequenceNumber,
121
+ messageReferenceSequenceNumber: messageLike.referenceSequenceNumber,
122
+ messageMinimumSequenceNumber: messageLike.minimumSequenceNumber,
123
+ messageTimestamp: messageLike.timestamp,
124
+ });
125
+ //# sourceMapping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C,CAAC;IACL,eAAe,EAAE,WAAW,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ;IAC9E,qBAAqB,EAAE,WAAW,CAAC,cAAc;IACjD,2BAA2B,EAAE,WAAW,CAAC,oBAAoB;IAC7D,8BAA8B,EAAE,WAAW,CAAC,uBAAuB;IACnE,4BAA4B,EAAE,WAAW,CAAC,qBAAqB;IAC/D,gBAAgB,EAAE,WAAW,CAAC,SAAS;CACvC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tFluidErrorTypes,\n\tIGenericError,\n\tIErrorBase,\n\tITelemetryProperties,\n\tIUsageError,\n} from \"@fluidframework/core-interfaces\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\n\nimport {\n\tLoggingError,\n\tNORMALIZED_ERROR_TYPE,\n\tisExternalError,\n\tnormalizeError,\n\twrapError,\n} from \"./errorLogging\";\nimport { IFluidErrorBase } from \"./fluidErrorBase\";\n\n/**\n * Generic wrapper for an unrecognized/uncategorized error object\n */\nexport class GenericError extends LoggingError implements IGenericError, IFluidErrorBase {\n\treadonly errorType = FluidErrorTypes.genericError;\n\n\t/**\n\t * Create a new GenericError\n\t * @param message - Error message\n\t * @param error - inner error object\n\t * @param props - Telemetry props to include when the error is logged\n\t */\n\t// TODO: Use `unknown` instead (API breaking change because error is not just an input parameter, but a public member of the class)\n\t// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any\n\tconstructor(message: string, public readonly error?: any, props?: ITelemetryProperties) {\n\t\t// Don't try to log the inner error\n\t\tsuper(message, props, new Set([\"error\"]));\n\t}\n}\n\n/**\n * Error indicating an API is being used improperly resulting in an invalid operation.\n */\nexport class UsageError extends LoggingError implements IUsageError, IFluidErrorBase {\n\treadonly errorType = FluidErrorTypes.usageError;\n\n\tconstructor(message: string, props?: ITelemetryProperties) {\n\t\tsuper(message, { ...props, usageError: true });\n\t}\n}\n\n/**\n * DataCorruptionError indicates that we encountered definitive evidence that the data at rest\n * backing this container is corrupted, and this container would never be expected to load properly again\n */\nexport class DataCorruptionError extends LoggingError implements IErrorBase, IFluidErrorBase {\n\treadonly errorType = FluidErrorTypes.dataCorruptionError;\n\treadonly canRetry = false;\n\n\tconstructor(message: string, props: ITelemetryProperties) {\n\t\tsuper(message, { ...props, dataProcessingError: 1 });\n\t}\n}\n\n/**\n * Indicates we hit a fatal error while processing incoming data from the Fluid Service.\n *\n * @remarks\n *\n * The error will often originate in the dataStore or DDS implementation that is responding to incoming changes.\n * This differs from {@link DataCorruptionError} in that this may be a transient error that will not repro in another\n * client or session.\n */\nexport class DataProcessingError extends LoggingError implements IErrorBase, IFluidErrorBase {\n\t/**\n\t * {@inheritDoc IFluidErrorBase.errorType}\n\t */\n\tpublic readonly errorType = FluidErrorTypes.dataProcessingError;\n\n\tpublic readonly canRetry = false;\n\n\tprivate constructor(errorMessage: string) {\n\t\tsuper(errorMessage);\n\t}\n\n\t/**\n\t * Create a new `DataProcessingError` detected and raised within the Fluid Framework.\n\t */\n\tpublic static create(\n\t\terrorMessage: string,\n\t\tdataProcessingCodepath: string,\n\t\tsequencedMessage?: ISequencedDocumentMessage,\n\t\tprops: ITelemetryProperties = {},\n\t): IFluidErrorBase {\n\t\tconst dataProcessingError = DataProcessingError.wrapIfUnrecognized(\n\t\t\terrorMessage,\n\t\t\tdataProcessingCodepath,\n\t\t\tsequencedMessage,\n\t\t);\n\t\tdataProcessingError.addTelemetryProperties(props);\n\n\t\treturn dataProcessingError;\n\t}\n\n\t/**\n\t * Wrap the given error in a `DataProcessingError`, unless the error is already of a known type\n\t * with the exception of a normalized {@link LoggingError}, which will still be wrapped.\n\t *\n\t * In either case, the error will have some relevant properties added for telemetry.\n\t *\n\t * @remarks\n\t *\n\t * We wrap conditionally since known error types represent well-understood failure modes, and ideally\n\t * one day we will move away from throwing these errors but rather we'll return them.\n\t * But an unrecognized error needs to be classified as `DataProcessingError`.\n\t *\n\t * @param originalError - The error to be converted.\n\t * @param dataProcessingCodepath - Which code-path failed while processing data.\n\t * @param messageLike - Message to include info about via telemetry props.\n\t *\n\t * @returns Either a new `DataProcessingError`, or (if wrapping is deemed unnecessary) the given error.\n\t */\n\tpublic static wrapIfUnrecognized(\n\t\toriginalError: unknown,\n\t\tdataProcessingCodepath: string,\n\t\tmessageLike?: Partial<\n\t\t\tPick<\n\t\t\t\tISequencedDocumentMessage,\n\t\t\t\t| \"clientId\"\n\t\t\t\t| \"sequenceNumber\"\n\t\t\t\t| \"clientSequenceNumber\"\n\t\t\t\t| \"referenceSequenceNumber\"\n\t\t\t\t| \"minimumSequenceNumber\"\n\t\t\t\t| \"timestamp\"\n\t\t\t>\n\t\t>,\n\t): IFluidErrorBase {\n\t\tconst props = {\n\t\t\tdataProcessingError: 1,\n\t\t\tdataProcessingCodepath,\n\t\t\t...(messageLike === undefined\n\t\t\t\t? undefined\n\t\t\t\t: extractSafePropertiesFromMessage(messageLike)),\n\t\t};\n\n\t\tconst normalizedError = normalizeError(originalError, { props });\n\t\t// Note that other errors may have the NORMALIZED_ERROR_TYPE errorType,\n\t\t// but if so they are still suitable to be wrapped as DataProcessingError.\n\t\tif (\n\t\t\tisExternalError(normalizedError) ||\n\t\t\tnormalizedError.errorType === NORMALIZED_ERROR_TYPE\n\t\t) {\n\t\t\t// Create a new DataProcessingError to wrap this external error\n\t\t\tconst dataProcessingError = wrapError(\n\t\t\t\tnormalizedError,\n\t\t\t\t(message: string) => new DataProcessingError(message),\n\t\t\t);\n\n\t\t\t// Copy over the props above and any others added to this error since first being normalized\n\t\t\tdataProcessingError.addTelemetryProperties(normalizedError.getTelemetryProperties());\n\n\t\t\treturn dataProcessingError;\n\t\t}\n\t\treturn normalizedError;\n\t}\n}\n\n/**\n * Extracts specific properties from the provided message that we know are safe to log.\n *\n * @param messageLike - Message to include info about via telemetry props.\n */\nexport const extractSafePropertiesFromMessage = (\n\tmessageLike: Partial<\n\t\tPick<\n\t\t\tISequencedDocumentMessage,\n\t\t\t| \"clientId\"\n\t\t\t| \"sequenceNumber\"\n\t\t\t| \"clientSequenceNumber\"\n\t\t\t| \"referenceSequenceNumber\"\n\t\t\t| \"minimumSequenceNumber\"\n\t\t\t| \"timestamp\"\n\t\t>\n\t>,\n): {\n\tmessageClientId: string | undefined;\n\tmessageSequenceNumber: number | undefined;\n\tmessageClientSequenceNumber: number | undefined;\n\tmessageReferenceSequenceNumber: number | undefined;\n\tmessageMinimumSequenceNumber: number | undefined;\n\tmessageTimestamp: number | undefined;\n} => ({\n\tmessageClientId: messageLike.clientId === null ? \"null\" : messageLike.clientId,\n\tmessageSequenceNumber: messageLike.sequenceNumber,\n\tmessageClientSequenceNumber: messageLike.clientSequenceNumber,\n\tmessageReferenceSequenceNumber: messageLike.referenceSequenceNumber,\n\tmessageMinimumSequenceNumber: messageLike.minimumSequenceNumber,\n\tmessageTimestamp: messageLike.timestamp,\n});\n"]}
@@ -5,17 +5,25 @@
5
5
  import { ILoggingError, ITaggedTelemetryPropertyType, ITelemetryProperties } from "@fluidframework/core-interfaces";
6
6
  import { IFluidErrorBase } from "./fluidErrorBase";
7
7
  import { ITaggedTelemetryPropertyTypeExt, ITelemetryLoggerExt, TelemetryEventPropertyTypeExt } from "./telemetryTypes";
8
- /** Inspect the given error for common "safe" props and return them */
9
- export declare function extractLogSafeErrorProperties(error: any, sanitizeStack: boolean): {
8
+ /**
9
+ * Inspect the given error for common "safe" props and return them.
10
+ */
11
+ export declare function extractLogSafeErrorProperties(error: unknown, sanitizeStack: boolean): {
10
12
  message: string;
11
13
  errorType?: string | undefined;
12
14
  stack?: string | undefined;
13
15
  };
14
- /** type guard for ILoggingError interface */
15
- export declare const isILoggingError: (x: any) => x is ILoggingError;
16
- /** Metadata to annotate an error object when annotating or normalizing it */
16
+ /**
17
+ * type guard for ILoggingError interface
18
+ */
19
+ export declare const isILoggingError: (x: unknown) => x is ILoggingError;
20
+ /**
21
+ * Metadata to annotate an error object when annotating or normalizing it
22
+ */
17
23
  export interface IFluidErrorAnnotations {
18
- /** Telemetry props to log with the error */
24
+ /**
25
+ * Telemetry props to log with the error
26
+ */
19
27
  props?: ITelemetryProperties;
20
28
  }
21
29
  /**
@@ -44,14 +52,18 @@ export declare function generateStack(): string | undefined;
44
52
  * @returns A new error object "wrapping" the given error
45
53
  */
46
54
  export declare function wrapError<T extends LoggingError>(innerError: unknown, newErrorFn: (message: string) => T): T;
47
- /** The same as wrapError, but also logs the innerError, including the wrapping error's instance id */
55
+ /**
56
+ * The same as wrapError, but also logs the innerError, including the wrapping error's instance ID.
57
+ *
58
+ * @typeParam T - The kind of wrapper error to create.
59
+ */
48
60
  export declare function wrapErrorAndLog<T extends LoggingError>(innerError: unknown, newErrorFn: (message: string) => T, logger: ITelemetryLoggerExt): T;
49
61
  /**
50
62
  * True for any error object that is an (optionally normalized) external error
51
63
  * False for any error we created and raised within the FF codebase via LoggingError base class,
52
64
  * or wrapped in a well-known error type
53
65
  */
54
- export declare function isExternalError(e: any): boolean;
66
+ export declare function isExternalError(error: unknown): boolean;
55
67
  /**
56
68
  * Type guard to identify if a particular telemetry property appears to be a tagged telemetry property
57
69
  */
@@ -63,7 +75,7 @@ export declare function isTaggedTelemetryPropertyValue(x: ITaggedTelemetryProper
63
75
  * Not ideal, as will cut values that are not necessarily circular references.
64
76
  * Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)
65
77
  */
66
- export declare const getCircularReplacer: () => (key: string, value: any) => any;
78
+ export declare const getCircularReplacer: () => (key: string, value: unknown) => any;
67
79
  /**
68
80
  * Base class for "trusted" errors we create, whose properties can generally be logged to telemetry safely.
69
81
  * All properties set on the object, or passed in (via the constructor or addTelemetryProperties),
@@ -76,7 +88,9 @@ export declare class LoggingError extends Error implements ILoggingError, Omit<I
76
88
  private _errorInstanceId;
77
89
  get errorInstanceId(): string;
78
90
  overwriteErrorInstanceId(id: string): void;
79
- /** Back-compat to appease isFluidError typeguard in old code that may handle this error */
91
+ /**
92
+ * Backwards compatibility to appease {@link isFluidError} in old code that may handle this error.
93
+ */
80
94
  private readonly fluidErrorCode;
81
95
  /**
82
96
  * Create a new LoggingError
@@ -100,6 +114,8 @@ export declare class LoggingError extends Error implements ILoggingError, Omit<I
100
114
  */
101
115
  getTelemetryProperties(): ITelemetryProperties;
102
116
  }
103
- /** The Error class used when normalizing an external error */
117
+ /**
118
+ * The Error class used when normalizing an external error
119
+ */
104
120
  export declare const NORMALIZED_ERROR_TYPE = "genericError";
105
121
  //# sourceMappingURL=errorLogging.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errorLogging.d.ts","sourceRoot":"","sources":["../src/errorLogging.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,aAAa,EACb,4BAA4B,EAC5B,oBAAoB,EAEpB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAEN,eAAe,EAGf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,+BAA+B,EAC/B,mBAAmB,EACnB,6BAA6B,EAC7B,MAAM,kBAAkB,CAAC;AAO1B,sEAAsE;AACtE,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,OAAO;aAenD,MAAM;;;EAkBlC;AAED,6CAA6C;AAC7C,eAAO,MAAM,eAAe,MAAO,GAAG,uBACU,CAAC;AAWjD,6EAA6E;AAC7E,MAAM,WAAW,sBAAsB;IACtC,4CAA4C;IAC5C,KAAK,CAAC,EAAE,oBAAoB,CAAC;CAC7B;AAYD;;;;;GAKG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,OAAO,EACd,WAAW,GAAE,sBAA2B,GACtC,eAAe,CAqDjB;AAID;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,IAAI,KAAK,CAgB9C;AAED,wBAAgB,aAAa,IAAI,MAAM,GAAG,SAAS,CAElD;AAED;;;;;;GAMG;AACH,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AM,EAAE,mBAAmB,GACzB,CAAC,CAmBH;AAWD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAWvD;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAC7C,CAAC,EAAE,+BAA+B,GAAG,6BAA6B,GAChE,CAAC,IAAI,4BAA4B,GAAG,+BAA+B,CAErE;AAwDD;;;;;;GAMG;AAGH,eAAO,MAAM,mBAAmB,cAAc,MAAM,SAAS,OAAO,KAAK,GAWxE,CAAC;AAGF;;;;;;GAMG;AACH,qBAAa,YACZ,SAAQ,KACR,YAAW,aAAa,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC;IA0B3D,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IAxBtC,OAAO,CAAC,gBAAgB,CAAU;IAClC,IAAI,eAAe,IAAI,MAAM,CAE5B;IACD,wBAAwB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAI1C;;OAEG;IAGH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAY;IAE3C;;;;;OAKG;gBAEF,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,oBAAoB,EACX,oBAAoB,GAAE,GAAG,CAAC,MAAM,CAAa;IAa/D;;;;OAIG;WACW,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,YAAY;IAWhE;;OAEG;IACI,sBAAsB,CAAC,KAAK,EAAE,oBAAoB,GAAG,IAAI;IAIhE;;OAEG;IACI,sBAAsB,IAAI,oBAAoB;CAUrD;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,iBAAiB,CAAC"}
@@ -4,11 +4,15 @@
4
4
  */
5
5
  import { v4 as uuid } from "uuid";
6
6
  import { hasErrorInstanceId, isFluidError, isValidLegacyError, } from "./fluidErrorBase";
7
- /** @returns true if value is an object but neither null nor an array */
7
+ /**
8
+ * Determines if the provided value is an object but neither null nor an array.
9
+ */
8
10
  const isRegularObject = (value) => {
9
11
  return value !== null && !Array.isArray(value) && typeof value === "object";
10
12
  };
11
- /** Inspect the given error for common "safe" props and return them */
13
+ /**
14
+ * Inspect the given error for common "safe" props and return them.
15
+ */
12
16
  export function extractLogSafeErrorProperties(error, sanitizeStack) {
13
17
  const removeMessageFromStack = (stack, errorName) => {
14
18
  if (!sanitizeStack) {
@@ -21,7 +25,9 @@ export function extractLogSafeErrorProperties(error, sanitizeStack) {
21
25
  }
22
26
  return stackFrames.join("\n");
23
27
  };
24
- const message = typeof error?.message === "string" ? error.message : String(error);
28
+ const message = typeof error?.message === "string"
29
+ ? error.message
30
+ : String(error);
25
31
  const safeProps = {
26
32
  message,
27
33
  };
@@ -37,9 +43,13 @@ export function extractLogSafeErrorProperties(error, sanitizeStack) {
37
43
  }
38
44
  return safeProps;
39
45
  }
40
- /** type guard for ILoggingError interface */
46
+ /**
47
+ * type guard for ILoggingError interface
48
+ */
41
49
  export const isILoggingError = (x) => typeof x?.getTelemetryProperties === "function";
42
- /** Copy props from source onto target, but do not overwrite an existing prop that matches */
50
+ /**
51
+ * Copy props from source onto target, but do not overwrite an existing prop that matches
52
+ */
43
53
  function copyProps(target, source) {
44
54
  for (const key of Object.keys(source)) {
45
55
  if (target[key] === undefined) {
@@ -47,8 +57,11 @@ function copyProps(target, source) {
47
57
  }
48
58
  }
49
59
  }
50
- /** For backwards compatibility with pre-errorInstanceId valid errors */
60
+ /**
61
+ * For backwards compatibility with pre-errorInstanceId valid errors
62
+ */
51
63
  function patchLegacyError(legacyError) {
64
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
52
65
  const patchMe = legacyError;
53
66
  if (patchMe.errorInstanceId === undefined) {
54
67
  patchMe.errorInstanceId = uuid();
@@ -128,8 +141,8 @@ export function generateErrorWithStack() {
128
141
  try {
129
142
  throw err;
130
143
  }
131
- catch (e) {
132
- return e;
144
+ catch (error) {
145
+ return error;
133
146
  }
134
147
  }
135
148
  export function generateStack() {
@@ -165,7 +178,11 @@ export function wrapError(innerError, newErrorFn) {
165
178
  }
166
179
  return newError;
167
180
  }
168
- /** The same as wrapError, but also logs the innerError, including the wrapping error's instance id */
181
+ /**
182
+ * The same as wrapError, but also logs the innerError, including the wrapping error's instance ID.
183
+ *
184
+ * @typeParam T - The kind of wrapper error to create.
185
+ */
169
186
  export function wrapErrorAndLog(innerError, newErrorFn, logger) {
170
187
  const newError = wrapError(innerError, newErrorFn);
171
188
  // This will match innerError.errorInstanceId if present (see wrapError)
@@ -184,7 +201,7 @@ function overwriteStack(error, stack) {
184
201
  try {
185
202
  Object.assign(error, { stack });
186
203
  }
187
- catch (errorSettingStack) {
204
+ catch {
188
205
  error.addTelemetryProperties({ stack2: stack });
189
206
  }
190
207
  }
@@ -193,17 +210,17 @@ function overwriteStack(error, stack) {
193
210
  * False for any error we created and raised within the FF codebase via LoggingError base class,
194
211
  * or wrapped in a well-known error type
195
212
  */
196
- export function isExternalError(e) {
213
+ export function isExternalError(error) {
197
214
  // LoggingErrors are an internal FF error type. However, an external error can be converted
198
215
  // into a LoggingError if it is normalized. In this case we must use the untrustedOrigin flag to
199
216
  // determine whether the original error was infact external.
200
- if (LoggingError.typeCheck(e)) {
201
- if (e.errorType === NORMALIZED_ERROR_TYPE) {
202
- return e.getTelemetryProperties().untrustedOrigin === 1;
217
+ if (LoggingError.typeCheck(error)) {
218
+ if (error.errorType === NORMALIZED_ERROR_TYPE) {
219
+ return error.getTelemetryProperties().untrustedOrigin === 1;
203
220
  }
204
221
  return false;
205
222
  }
206
- return !isValidLegacyError(e);
223
+ return !isValidLegacyError(error);
207
224
  }
208
225
  /**
209
226
  * Type guard to identify if a particular telemetry property appears to be a tagged telemetry property
@@ -270,6 +287,8 @@ function getValidTelemetryProps(obj, keysToOmit) {
270
287
  * Not ideal, as will cut values that are not necessarily circular references.
271
288
  * Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)
272
289
  */
290
+ // TODO: Use `unknown` instead (API breaking change)
291
+ /* eslint-disable @typescript-eslint/no-explicit-any */
273
292
  export const getCircularReplacer = () => {
274
293
  const seen = new WeakSet();
275
294
  return (key, value) => {
@@ -282,6 +301,7 @@ export const getCircularReplacer = () => {
282
301
  return value;
283
302
  };
284
303
  };
304
+ /* eslint-enable @typescript-eslint/no-explicit-any */
285
305
  /**
286
306
  * Base class for "trusted" errors we create, whose properties can generally be logged to telemetry safely.
287
307
  * All properties set on the object, or passed in (via the constructor or addTelemetryProperties),
@@ -300,8 +320,11 @@ export class LoggingError extends Error {
300
320
  super(message);
301
321
  this.omitPropsFromLogging = omitPropsFromLogging;
302
322
  this._errorInstanceId = uuid();
303
- /** Back-compat to appease isFluidError typeguard in old code that may handle this error */
323
+ /**
324
+ * Backwards compatibility to appease {@link isFluidError} in old code that may handle this error.
325
+ */
304
326
  // @ts-expect-error - This field shouldn't be referenced in the current version, but needs to exist at runtime.
327
+ // eslint-disable-next-line @typescript-eslint/prefer-as-const
305
328
  this.fluidErrorCode = "-";
306
329
  // Don't log this list itself, or the private _errorInstanceId
307
330
  omitPropsFromLogging.add("omitPropsFromLogging");
@@ -349,7 +372,9 @@ export class LoggingError extends Error {
349
372
  };
350
373
  }
351
374
  }
352
- /** The Error class used when normalizing an external error */
375
+ /**
376
+ * The Error class used when normalizing an external error
377
+ */
353
378
  export const NORMALIZED_ERROR_TYPE = "genericError";
354
379
  class NormalizedLoggingError extends LoggingError {
355
380
  constructor(errorProps) {
@@ -1 +1 @@
1
- {"version":3,"file":"errorLogging.js","sourceRoot":"","sources":["../src/errorLogging.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EACN,kBAAkB,EAElB,YAAY,EACZ,kBAAkB,GAClB,MAAM,kBAAkB,CAAC;AAO1B,wEAAwE;AACxE,MAAM,eAAe,GAAG,CAAC,KAAU,EAAW,EAAE;IAC/C,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OA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AuB,CAAC,eAAe,KAAK,QAAQ,CAC5D,CAAC;SACF;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAED;;OAEG;IACI,sBAAsB,CAAC,KAA2B;QACxD,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;IAED;;OAEG;IACI,sBAAsB;QAC5B,MAAM,aAAa,GAAG,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC9E,+EAA+E;QAC/E,OAAO;YACN,GAAG,aAAa;YAChB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,eAAe,EAAE,IAAI,CAAC,gBAAgB;SACtC,CAAC;IACH,CAAC;CACD;AAED,8DAA8D;AAC9D,MAAM,CAAC,MAAM,qBAAqB,GAAG,cAAc,CAAC;AACpD,MAAM,sBAAuB,SAAQ,YAAY;IAKhD,YAAY,UAAsD;QACjE,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAL3B,2EAA2E;QAC3E,2EAA2E;QAC3E,cAAS,GAAG,qBAAqB,CAAC;QAKjC,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE;YACnC,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;SACvC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tILoggingError,\n\tITaggedTelemetryPropertyType,\n\tITelemetryProperties,\n\tTelemetryEventPropertyType,\n} from \"@fluidframework/core-interfaces\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n\thasErrorInstanceId,\n\tIFluidErrorBase,\n\tisFluidError,\n\tisValidLegacyError,\n} from \"./fluidErrorBase\";\nimport {\n\tITaggedTelemetryPropertyTypeExt,\n\tITelemetryLoggerExt,\n\tTelemetryEventPropertyTypeExt,\n} from \"./telemetryTypes\";\n\n/** @returns true if value is an object but neither null nor an array */\nconst isRegularObject = (value: any): boolean => {\n\treturn value !== null && !Array.isArray(value) && typeof value === \"object\";\n};\n\n/** Inspect the given error for common \"safe\" props and return them */\nexport function extractLogSafeErrorProperties(error: any, sanitizeStack: boolean) {\n\tconst removeMessageFromStack = (stack: string, errorName?: string) => {\n\t\tif (!sanitizeStack) {\n\t\t\treturn stack;\n\t\t}\n\t\tconst stackFrames = stack.split(\"\\n\");\n\t\tstackFrames.shift(); // Remove \"[ErrorName]: [ErrorMessage]\"\n\t\tif (errorName !== undefined) {\n\t\t\tstackFrames.unshift(errorName); // Add \"[ErrorName]\"\n\t\t}\n\t\treturn stackFrames.join(\"\\n\");\n\t};\n\n\tconst message = typeof error?.message === \"string\" ? (error.message as string) : String(error);\n\n\tconst safeProps: { message: string; errorType?: string; stack?: string } = {\n\t\tmessage,\n\t};\n\n\tif (isRegularObject(error)) {\n\t\tconst { errorType, stack, name } = error;\n\n\t\tif (typeof errorType === \"string\") {\n\t\t\tsafeProps.errorType = errorType;\n\t\t}\n\n\t\tif (typeof stack === \"string\") {\n\t\t\tconst errorName = typeof name === \"string\" ? name : undefined;\n\t\t\tsafeProps.stack = removeMessageFromStack(stack, errorName);\n\t\t}\n\t}\n\n\treturn safeProps;\n}\n\n/** type guard for ILoggingError interface */\nexport const isILoggingError = (x: any): x is ILoggingError =>\n\ttypeof x?.getTelemetryProperties === \"function\";\n\n/** Copy props from source onto target, but do not overwrite an existing prop that matches */\nfunction copyProps(target: ITelemetryProperties | LoggingError, source: ITelemetryProperties) {\n\tfor (const key of Object.keys(source)) {\n\t\tif (target[key] === undefined) {\n\t\t\ttarget[key] = source[key];\n\t\t}\n\t}\n}\n\n/** Metadata to annotate an error object when annotating or normalizing it */\nexport interface IFluidErrorAnnotations {\n\t/** Telemetry props to log with the error */\n\tprops?: ITelemetryProperties;\n}\n\n/** For backwards compatibility with pre-errorInstanceId valid errors */\nfunction patchLegacyError(\n\tlegacyError: Omit<IFluidErrorBase, \"errorInstanceId\">,\n): asserts legacyError is IFluidErrorBase {\n\tconst patchMe: { -readonly [P in \"errorInstanceId\"]?: IFluidErrorBase[P] } = legacyError as any;\n\tif (patchMe.errorInstanceId === undefined) {\n\t\tpatchMe.errorInstanceId = uuid();\n\t}\n}\n\n/**\n * Normalize the given error yielding a valid Fluid Error\n * @returns A valid Fluid Error with any provided annotations applied\n * @param error - The error to normalize\n * @param annotations - Annotations to apply to the normalized error\n */\nexport function normalizeError(\n\terror: unknown,\n\tannotations: IFluidErrorAnnotations = {},\n): IFluidErrorBase {\n\t// Back-compat, while IFluidErrorBase is rolled out\n\tif (isValidLegacyError(error)) {\n\t\tpatchLegacyError(error);\n\t}\n\n\tif (isFluidError(error)) {\n\t\t// We can simply add the telemetry props to the error and return it\n\t\terror.addTelemetryProperties(annotations.props ?? {});\n\t\treturn error;\n\t}\n\n\t// We have to construct a new Fluid Error, copying safe properties over\n\tconst { message, stack } = extractLogSafeErrorProperties(error, false /* sanitizeStack */);\n\tconst fluidError: IFluidErrorBase = new NormalizedLoggingError({\n\t\tmessage,\n\t\tstack,\n\t});\n\n\t// We need to preserve these properties which are used in a non-typesafe way throughout driver code (see #8743)\n\t// Anywhere they are set should be on a valid Fluid Error that would have been returned above,\n\t// but we can't prove it with the types, so adding this defensive measure.\n\tif (typeof error === \"object\" && error !== null) {\n\t\tconst maybeHasRetry: Partial<Record<\"canRetry\" | \"retryAfterSeconds\", unknown>> = error;\n\t\tlet retryProps: Partial<Record<\"canRetry\" | \"retryAfterSeconds\", unknown>> | undefined;\n\t\tif (\"canRetry\" in error) {\n\t\t\tretryProps ??= {};\n\t\t\tretryProps.canRetry = maybeHasRetry.canRetry;\n\t\t}\n\t\tif (\"retryAfterSeconds\" in error) {\n\t\t\tretryProps ??= {};\n\t\t\tretryProps.retryAfterSeconds = maybeHasRetry.retryAfterSeconds;\n\t\t}\n\t\tif (retryProps !== undefined) {\n\t\t\tObject.assign(fluidError, retryProps);\n\t\t}\n\t}\n\n\tif (typeof error !== \"object\") {\n\t\t// This is only interesting for non-objects\n\t\tfluidError.addTelemetryProperties({ typeofError: typeof error });\n\t}\n\n\tconst errorTelemetryProps = LoggingError.typeCheck(error)\n\t\t? error.getTelemetryProperties()\n\t\t: { untrustedOrigin: 1 }; // This will let us filter errors that did not originate from our own codebase\n\n\tfluidError.addTelemetryProperties({\n\t\t...errorTelemetryProps,\n\t\t...annotations.props,\n\t});\n\n\treturn fluidError;\n}\n\nlet stackPopulatedOnCreation: boolean | undefined;\n\n/**\n * The purpose of this function is to provide ability to capture stack context quickly.\n * Accessing new Error().stack is slow, and the slowest part is accessing stack property itself.\n * There are scenarios where we generate error with stack, but error is handled in most cases and\n * stack property is not accessed.\n * For such cases it's better to not read stack property right away, but rather delay it until / if it's needed\n * Some browsers will populate stack right away, others require throwing Error, so we do auto-detection on the fly.\n * @returns Error object that has stack populated.\n */\nexport function generateErrorWithStack(): Error {\n\tconst err = new Error(\"<<generated stack>>\");\n\n\tif (stackPopulatedOnCreation === undefined) {\n\t\tstackPopulatedOnCreation = err.stack !== undefined;\n\t}\n\n\tif (stackPopulatedOnCreation) {\n\t\treturn err;\n\t}\n\n\ttry {\n\t\tthrow err;\n\t} catch (e) {\n\t\treturn e as Error;\n\t}\n}\n\nexport function generateStack(): string | undefined {\n\treturn generateErrorWithStack().stack;\n}\n\n/**\n * Create a new error using newErrorFn, wrapping and caused by the given unknown error.\n * Copies the inner error's stack, errorInstanceId and telemetry props over to the new error if present\n * @param innerError - An error from untrusted/unknown origins\n * @param newErrorFn - callback that will create a new error given the original error's message\n * @returns A new error object \"wrapping\" the given error\n */\nexport function wrapError<T extends LoggingError>(\n\tinnerError: unknown,\n\tnewErrorFn: (message: string) => T,\n): T {\n\tconst { message, stack } = extractLogSafeErrorProperties(innerError, false /* sanitizeStack */);\n\n\tconst newError = newErrorFn(message);\n\n\tif (stack !== undefined) {\n\t\toverwriteStack(newError, stack);\n\t}\n\n\t// Mark external errors with untrustedOrigin flag\n\tif (isExternalError(innerError)) {\n\t\tnewError.addTelemetryProperties({ untrustedOrigin: 1 });\n\t}\n\n\t// Reuse errorInstanceId\n\tif (hasErrorInstanceId(innerError)) {\n\t\tnewError.overwriteErrorInstanceId(innerError.errorInstanceId);\n\n\t\t// For \"back-compat\" in the logs\n\t\tnewError.addTelemetryProperties({ innerErrorInstanceId: innerError.errorInstanceId });\n\t}\n\n\t// Lastly, copy over all other telemetry properties. Note these will not overwrite existing properties\n\t// This will include the untrustedOrigin property if the inner error itself was created from an external error\n\tif (isILoggingError(innerError)) {\n\t\tnewError.addTelemetryProperties(innerError.getTelemetryProperties());\n\t}\n\n\treturn newError;\n}\n\n/** The same as wrapError, but also logs the innerError, including the wrapping error's instance id */\nexport function wrapErrorAndLog<T extends LoggingError>(\n\tinnerError: unknown,\n\tnewErrorFn: (message: string) => T,\n\tlogger: ITelemetryLoggerExt,\n) {\n\tconst newError = wrapError(innerError, newErrorFn);\n\n\t// This will match innerError.errorInstanceId if present (see wrapError)\n\tconst errorInstanceId = newError.errorInstanceId;\n\n\t// For \"back-compat\" in the logs\n\tconst wrappedByErrorInstanceId = errorInstanceId;\n\n\tlogger.sendTelemetryEvent(\n\t\t{\n\t\t\teventName: \"WrapError\",\n\t\t\terrorInstanceId,\n\t\t\twrappedByErrorInstanceId,\n\t\t},\n\t\tinnerError,\n\t);\n\n\treturn newError;\n}\n\nfunction overwriteStack(error: IFluidErrorBase | LoggingError, stack: string) {\n\t// supposedly setting stack on an Error can throw.\n\ttry {\n\t\tObject.assign(error, { stack });\n\t} catch (errorSettingStack) {\n\t\terror.addTelemetryProperties({ stack2: stack });\n\t}\n}\n\n/**\n * True for any error object that is an (optionally normalized) external error\n * False for any error we created and raised within the FF codebase via LoggingError base class,\n * or wrapped in a well-known error type\n */\nexport function isExternalError(e: any): boolean {\n\t// LoggingErrors are an internal FF error type. However, an external error can be converted\n\t// into a LoggingError if it is normalized. In this case we must use the untrustedOrigin flag to\n\t// determine whether the original error was infact external.\n\tif (LoggingError.typeCheck(e)) {\n\t\tif ((e as NormalizedLoggingError).errorType === NORMALIZED_ERROR_TYPE) {\n\t\t\treturn e.getTelemetryProperties().untrustedOrigin === 1;\n\t\t}\n\t\treturn false;\n\t}\n\treturn !isValidLegacyError(e);\n}\n\n/**\n * Type guard to identify if a particular telemetry property appears to be a tagged telemetry property\n */\nexport function isTaggedTelemetryPropertyValue(\n\tx: ITaggedTelemetryPropertyTypeExt | TelemetryEventPropertyTypeExt,\n): x is ITaggedTelemetryPropertyType | ITaggedTelemetryPropertyTypeExt {\n\treturn typeof (x as any)?.tag === \"string\";\n}\n\n/**\n * Filter serializable telemetry properties\n * @param x - any telemetry prop\n * @returns - as-is if x is primitive. returns stringified if x is an array of primitive.\n * otherwise returns null since this is what we support at the moment.\n */\nfunction filterValidTelemetryProps(x: any, key: string): TelemetryEventPropertyType {\n\tif (Array.isArray(x) && x.every((val) => isTelemetryEventPropertyValue(val))) {\n\t\treturn JSON.stringify(x);\n\t}\n\tif (isTelemetryEventPropertyValue(x)) {\n\t\treturn x;\n\t}\n\t// We don't support logging arbitrary objects\n\tconsole.error(`UnSupported Format of Logging Error Property for key ${key}:`, x);\n\treturn \"REDACTED (arbitrary object)\";\n}\n\n// checking type of x, returns false if x is null\nfunction isTelemetryEventPropertyValue(x: any): x is TelemetryEventPropertyType {\n\tswitch (typeof x) {\n\t\tcase \"string\":\n\t\tcase \"number\":\n\t\tcase \"boolean\":\n\t\tcase \"undefined\":\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n/**\n * Walk an object's enumerable properties to find those fit for telemetry.\n */\nfunction getValidTelemetryProps(obj: any, keysToOmit: Set<string>): ITelemetryProperties {\n\tconst props: ITelemetryProperties = {};\n\tfor (const key of Object.keys(obj)) {\n\t\tif (keysToOmit.has(key)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst val = obj[key];\n\n\t\t// ensure only valid props get logged, since props of logging error could be in any shape\n\t\tif (isTaggedTelemetryPropertyValue(val)) {\n\t\t\tprops[key] = {\n\t\t\t\tvalue: filterValidTelemetryProps(val.value, key),\n\t\t\t\ttag: val.tag,\n\t\t\t};\n\t\t} else {\n\t\t\tprops[key] = filterValidTelemetryProps(val, key);\n\t\t}\n\t}\n\treturn props;\n}\n\n/**\n * Borrowed from\n * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#examples}\n * Avoids runtime errors with circular references.\n * Not ideal, as will cut values that are not necessarily circular references.\n * Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)\n */\nexport const getCircularReplacer = () => {\n\tconst seen = new WeakSet();\n\treturn (key: string, value: any): any => {\n\t\tif (typeof value === \"object\" && value !== null) {\n\t\t\tif (seen.has(value)) {\n\t\t\t\treturn \"<removed/circular>\";\n\t\t\t}\n\t\t\tseen.add(value);\n\t\t}\n\t\treturn value;\n\t};\n};\n\n/**\n * Base class for \"trusted\" errors we create, whose properties can generally be logged to telemetry safely.\n * All properties set on the object, or passed in (via the constructor or addTelemetryProperties),\n * will be logged in accordance with their tag, if present.\n *\n * PLEASE take care to avoid setting sensitive data on this object without proper tagging!\n */\nexport class LoggingError\n\textends Error\n\timplements ILoggingError, Omit<IFluidErrorBase, \"errorType\">\n{\n\tprivate _errorInstanceId = uuid();\n\tget errorInstanceId() {\n\t\treturn this._errorInstanceId;\n\t}\n\toverwriteErrorInstanceId(id: string) {\n\t\tthis._errorInstanceId = id;\n\t}\n\n\t/** Back-compat to appease isFluidError typeguard in old code that may handle this error */\n\t// @ts-expect-error - This field shouldn't be referenced in the current version, but needs to exist at runtime.\n\tprivate readonly fluidErrorCode: \"-\" = \"-\";\n\n\t/**\n\t * Create a new LoggingError\n\t * @param message - Error message to use for Error base class\n\t * @param props - telemetry props to include on the error for when it's logged\n\t * @param omitPropsFromLogging - properties by name to omit from telemetry props\n\t */\n\tconstructor(\n\t\tmessage: string,\n\t\tprops?: ITelemetryProperties,\n\t\tprivate readonly omitPropsFromLogging: Set<string> = new Set(),\n\t) {\n\t\tsuper(message);\n\n\t\t// Don't log this list itself, or the private _errorInstanceId\n\t\tomitPropsFromLogging.add(\"omitPropsFromLogging\");\n\t\tomitPropsFromLogging.add(\"_errorInstanceId\");\n\n\t\tif (props) {\n\t\t\tthis.addTelemetryProperties(props);\n\t\t}\n\t}\n\n\t/**\n\t * Determines if a given object is an instance of a LoggingError\n\t * @param object - any object\n\t * @returns - true if the object is an instance of a LoggingError, false if not.\n\t */\n\tpublic static typeCheck(object: unknown): object is LoggingError {\n\t\tif (typeof object === \"object\" && object !== null) {\n\t\t\treturn (\n\t\t\t\ttypeof (object as LoggingError).addTelemetryProperties === \"function\" &&\n\t\t\t\ttypeof (object as LoggingError).getTelemetryProperties === \"function\" &&\n\t\t\t\ttypeof (object as LoggingError).errorInstanceId === \"string\"\n\t\t\t);\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Add additional properties to be logged\n\t */\n\tpublic addTelemetryProperties(props: ITelemetryProperties) {\n\t\tcopyProps(this, props);\n\t}\n\n\t/**\n\t * Get all properties fit to be logged to telemetry for this error\n\t */\n\tpublic getTelemetryProperties(): ITelemetryProperties {\n\t\tconst taggableProps = getValidTelemetryProps(this, this.omitPropsFromLogging);\n\t\t// Include non-enumerable props that are not returned by getValidTelemetryProps\n\t\treturn {\n\t\t\t...taggableProps,\n\t\t\tstack: this.stack,\n\t\t\tmessage: this.message,\n\t\t\terrorInstanceId: this._errorInstanceId,\n\t\t};\n\t}\n}\n\n/** The Error class used when normalizing an external error */\nexport const NORMALIZED_ERROR_TYPE = \"genericError\";\nclass NormalizedLoggingError extends LoggingError {\n\t// errorType \"genericError\" is used as a default value throughout the code.\n\t// Note that this matches ContainerErrorType/DriverErrorType's genericError\n\terrorType = NORMALIZED_ERROR_TYPE;\n\n\tconstructor(errorProps: Pick<IFluidErrorBase, \"message\" | \"stack\">) {\n\t\tsuper(errorProps.message);\n\n\t\tif (errorProps.stack !== undefined) {\n\t\t\toverwriteStack(this, errorProps.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C;SACvC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tILoggingError,\n\tITaggedTelemetryPropertyType,\n\tITelemetryProperties,\n\tTelemetryEventPropertyType,\n} from \"@fluidframework/core-interfaces\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n\thasErrorInstanceId,\n\tIFluidErrorBase,\n\tisFluidError,\n\tisValidLegacyError,\n} from \"./fluidErrorBase\";\nimport {\n\tITaggedTelemetryPropertyTypeExt,\n\tITelemetryLoggerExt,\n\tTelemetryEventPropertyTypeExt,\n} from \"./telemetryTypes\";\n\n/**\n * Determines if the provided value is an object but neither null nor an array.\n */\nconst isRegularObject = (value: unknown): boolean => {\n\treturn value !== null && !Array.isArray(value) && typeof value === \"object\";\n};\n\n/**\n * Inspect the given error for common \"safe\" props and return them.\n */\nexport function extractLogSafeErrorProperties(\n\terror: unknown,\n\tsanitizeStack: boolean,\n): {\n\tmessage: string;\n\terrorType?: string | undefined;\n\tstack?: string | undefined;\n} {\n\tconst removeMessageFromStack = (stack: string, errorName?: string): string => {\n\t\tif (!sanitizeStack) {\n\t\t\treturn stack;\n\t\t}\n\t\tconst stackFrames = stack.split(\"\\n\");\n\t\tstackFrames.shift(); // Remove \"[ErrorName]: [ErrorMessage]\"\n\t\tif (errorName !== undefined) {\n\t\t\tstackFrames.unshift(errorName); // Add \"[ErrorName]\"\n\t\t}\n\t\treturn stackFrames.join(\"\\n\");\n\t};\n\n\tconst message =\n\t\ttypeof (error as Partial<Error>)?.message === \"string\"\n\t\t\t? (error as Error).message\n\t\t\t: String(error);\n\n\tconst safeProps: { message: string; errorType?: string; stack?: string } = {\n\t\tmessage,\n\t};\n\n\tif (isRegularObject(error)) {\n\t\tconst { errorType, stack, name } = error as Partial<IFluidErrorBase>;\n\n\t\tif (typeof errorType === \"string\") {\n\t\t\tsafeProps.errorType = errorType;\n\t\t}\n\n\t\tif (typeof stack === \"string\") {\n\t\t\tconst errorName = typeof name === \"string\" ? name : undefined;\n\t\t\tsafeProps.stack = removeMessageFromStack(stack, errorName);\n\t\t}\n\t}\n\n\treturn safeProps;\n}\n\n/**\n * type guard for ILoggingError interface\n */\nexport const isILoggingError = (x: unknown): x is ILoggingError =>\n\ttypeof (x as Partial<ILoggingError>)?.getTelemetryProperties === \"function\";\n\n/**\n * Copy props from source onto target, but do not overwrite an existing prop that matches\n */\nfunction copyProps(\n\ttarget: ITelemetryProperties | LoggingError,\n\tsource: ITelemetryProperties,\n): void {\n\tfor (const key of Object.keys(source)) {\n\t\tif (target[key] === undefined) {\n\t\t\ttarget[key] = source[key];\n\t\t}\n\t}\n}\n\n/**\n * Metadata to annotate an error object when annotating or normalizing it\n */\nexport interface IFluidErrorAnnotations {\n\t/**\n\t * Telemetry props to log with the error\n\t */\n\tprops?: ITelemetryProperties;\n}\n\n/**\n * For backwards compatibility with pre-errorInstanceId valid errors\n */\nfunction patchLegacyError(\n\tlegacyError: Omit<IFluidErrorBase, \"errorInstanceId\">,\n): asserts legacyError is IFluidErrorBase {\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any\n\tconst patchMe: { -readonly [P in \"errorInstanceId\"]?: IFluidErrorBase[P] } = legacyError as any;\n\tif (patchMe.errorInstanceId === undefined) {\n\t\tpatchMe.errorInstanceId = uuid();\n\t}\n}\n\n/**\n * Normalize the given error yielding a valid Fluid Error\n * @returns A valid Fluid Error with any provided annotations applied\n * @param error - The error to normalize\n * @param annotations - Annotations to apply to the normalized error\n */\nexport function normalizeError(\n\terror: unknown,\n\tannotations: IFluidErrorAnnotations = {},\n): IFluidErrorBase {\n\t// Back-compat, while IFluidErrorBase is rolled out\n\tif (isValidLegacyError(error)) {\n\t\tpatchLegacyError(error);\n\t}\n\n\tif (isFluidError(error)) {\n\t\t// We can simply add the telemetry props to the error and return it\n\t\terror.addTelemetryProperties(annotations.props ?? {});\n\t\treturn error;\n\t}\n\n\t// We have to construct a new Fluid Error, copying safe properties over\n\tconst { message, stack } = extractLogSafeErrorProperties(error, false /* sanitizeStack */);\n\tconst fluidError: IFluidErrorBase = new NormalizedLoggingError({\n\t\tmessage,\n\t\tstack,\n\t});\n\n\t// We need to preserve these properties which are used in a non-typesafe way throughout driver code (see #8743)\n\t// Anywhere they are set should be on a valid Fluid Error that would have been returned above,\n\t// but we can't prove it with the types, so adding this defensive measure.\n\tif (typeof error === \"object\" && error !== null) {\n\t\tconst maybeHasRetry: Partial<Record<\"canRetry\" | \"retryAfterSeconds\", unknown>> = error;\n\t\tlet retryProps: Partial<Record<\"canRetry\" | \"retryAfterSeconds\", unknown>> | undefined;\n\t\tif (\"canRetry\" in error) {\n\t\t\tretryProps ??= {};\n\t\t\tretryProps.canRetry = maybeHasRetry.canRetry;\n\t\t}\n\t\tif (\"retryAfterSeconds\" in error) {\n\t\t\tretryProps ??= {};\n\t\t\tretryProps.retryAfterSeconds = maybeHasRetry.retryAfterSeconds;\n\t\t}\n\t\tif (retryProps !== undefined) {\n\t\t\tObject.assign(fluidError, retryProps);\n\t\t}\n\t}\n\n\tif (typeof error !== \"object\") {\n\t\t// This is only interesting for non-objects\n\t\tfluidError.addTelemetryProperties({ typeofError: typeof error });\n\t}\n\n\tconst errorTelemetryProps = LoggingError.typeCheck(error)\n\t\t? error.getTelemetryProperties()\n\t\t: { untrustedOrigin: 1 }; // This will let us filter errors that did not originate from our own codebase\n\n\tfluidError.addTelemetryProperties({\n\t\t...errorTelemetryProps,\n\t\t...annotations.props,\n\t});\n\n\treturn fluidError;\n}\n\nlet stackPopulatedOnCreation: boolean | undefined;\n\n/**\n * The purpose of this function is to provide ability to capture stack context quickly.\n * Accessing new Error().stack is slow, and the slowest part is accessing stack property itself.\n * There are scenarios where we generate error with stack, but error is handled in most cases and\n * stack property is not accessed.\n * For such cases it's better to not read stack property right away, but rather delay it until / if it's needed\n * Some browsers will populate stack right away, others require throwing Error, so we do auto-detection on the fly.\n * @returns Error object that has stack populated.\n */\nexport function generateErrorWithStack(): Error {\n\tconst err = new Error(\"<<generated stack>>\");\n\n\tif (stackPopulatedOnCreation === undefined) {\n\t\tstackPopulatedOnCreation = err.stack !== undefined;\n\t}\n\n\tif (stackPopulatedOnCreation) {\n\t\treturn err;\n\t}\n\n\ttry {\n\t\tthrow err;\n\t} catch (error) {\n\t\treturn error as Error;\n\t}\n}\n\nexport function generateStack(): string | undefined {\n\treturn generateErrorWithStack().stack;\n}\n\n/**\n * Create a new error using newErrorFn, wrapping and caused by the given unknown error.\n * Copies the inner error's stack, errorInstanceId and telemetry props over to the new error if present\n * @param innerError - An error from untrusted/unknown origins\n * @param newErrorFn - callback that will create a new error given the original error's message\n * @returns A new error object \"wrapping\" the given error\n */\nexport function wrapError<T extends LoggingError>(\n\tinnerError: unknown,\n\tnewErrorFn: (message: string) => T,\n): T {\n\tconst { message, stack } = extractLogSafeErrorProperties(innerError, false /* sanitizeStack */);\n\n\tconst newError = newErrorFn(message);\n\n\tif (stack !== undefined) {\n\t\toverwriteStack(newError, stack);\n\t}\n\n\t// Mark external errors with untrustedOrigin flag\n\tif (isExternalError(innerError)) {\n\t\tnewError.addTelemetryProperties({ untrustedOrigin: 1 });\n\t}\n\n\t// Reuse errorInstanceId\n\tif (hasErrorInstanceId(innerError)) {\n\t\tnewError.overwriteErrorInstanceId(innerError.errorInstanceId);\n\n\t\t// For \"back-compat\" in the logs\n\t\tnewError.addTelemetryProperties({ innerErrorInstanceId: innerError.errorInstanceId });\n\t}\n\n\t// Lastly, copy over all other telemetry properties. Note these will not overwrite existing properties\n\t// This will include the untrustedOrigin property if the inner error itself was created from an external error\n\tif (isILoggingError(innerError)) {\n\t\tnewError.addTelemetryProperties(innerError.getTelemetryProperties());\n\t}\n\n\treturn newError;\n}\n\n/**\n * The same as wrapError, but also logs the innerError, including the wrapping error's instance ID.\n *\n * @typeParam T - The kind of wrapper error to create.\n */\nexport function wrapErrorAndLog<T extends LoggingError>(\n\tinnerError: unknown,\n\tnewErrorFn: (message: string) => T,\n\tlogger: ITelemetryLoggerExt,\n): T {\n\tconst newError = wrapError(innerError, newErrorFn);\n\n\t// This will match innerError.errorInstanceId if present (see wrapError)\n\tconst errorInstanceId = newError.errorInstanceId;\n\n\t// For \"back-compat\" in the logs\n\tconst wrappedByErrorInstanceId = errorInstanceId;\n\n\tlogger.sendTelemetryEvent(\n\t\t{\n\t\t\teventName: \"WrapError\",\n\t\t\terrorInstanceId,\n\t\t\twrappedByErrorInstanceId,\n\t\t},\n\t\tinnerError,\n\t);\n\n\treturn newError;\n}\n\nfunction overwriteStack(error: IFluidErrorBase | LoggingError, stack: string): void {\n\t// supposedly setting stack on an Error can throw.\n\ttry {\n\t\tObject.assign(error, { stack });\n\t} catch {\n\t\terror.addTelemetryProperties({ stack2: stack });\n\t}\n}\n\n/**\n * True for any error object that is an (optionally normalized) external error\n * False for any error we created and raised within the FF codebase via LoggingError base class,\n * or wrapped in a well-known error type\n */\nexport function isExternalError(error: unknown): boolean {\n\t// LoggingErrors are an internal FF error type. However, an external error can be converted\n\t// into a LoggingError if it is normalized. In this case we must use the untrustedOrigin flag to\n\t// determine whether the original error was infact external.\n\tif (LoggingError.typeCheck(error)) {\n\t\tif ((error as NormalizedLoggingError).errorType === NORMALIZED_ERROR_TYPE) {\n\t\t\treturn error.getTelemetryProperties().untrustedOrigin === 1;\n\t\t}\n\t\treturn false;\n\t}\n\treturn !isValidLegacyError(error);\n}\n\n/**\n * Type guard to identify if a particular telemetry property appears to be a tagged telemetry property\n */\nexport function isTaggedTelemetryPropertyValue(\n\tx: ITaggedTelemetryPropertyTypeExt | TelemetryEventPropertyTypeExt,\n): x is ITaggedTelemetryPropertyType | ITaggedTelemetryPropertyTypeExt {\n\treturn typeof (x as Partial<ITaggedTelemetryPropertyTypeExt>)?.tag === \"string\";\n}\n\n/**\n * Filter serializable telemetry properties\n * @param x - any telemetry prop\n * @returns - as-is if x is primitive. returns stringified if x is an array of primitive.\n * otherwise returns null since this is what we support at the moment.\n */\nfunction filterValidTelemetryProps(x: unknown, key: string): TelemetryEventPropertyType {\n\tif (Array.isArray(x) && x.every((val) => isTelemetryEventPropertyValue(val))) {\n\t\treturn JSON.stringify(x);\n\t}\n\tif (isTelemetryEventPropertyValue(x)) {\n\t\treturn x;\n\t}\n\t// We don't support logging arbitrary objects\n\tconsole.error(`UnSupported Format of Logging Error Property for key ${key}:`, x);\n\treturn \"REDACTED (arbitrary object)\";\n}\n\n// checking type of x, returns false if x is null\nfunction isTelemetryEventPropertyValue(x: unknown): x is TelemetryEventPropertyType {\n\tswitch (typeof x) {\n\t\tcase \"string\":\n\t\tcase \"number\":\n\t\tcase \"boolean\":\n\t\tcase \"undefined\":\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n/**\n * Walk an object's enumerable properties to find those fit for telemetry.\n */\nfunction getValidTelemetryProps(obj: object, keysToOmit: Set<string>): ITelemetryProperties {\n\tconst props: ITelemetryProperties = {};\n\tfor (const key of Object.keys(obj)) {\n\t\tif (keysToOmit.has(key)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst val = obj[key] as ITaggedTelemetryPropertyTypeExt | TelemetryEventPropertyTypeExt;\n\n\t\t// ensure only valid props get logged, since props of logging error could be in any shape\n\t\tif (isTaggedTelemetryPropertyValue(val)) {\n\t\t\tprops[key] = {\n\t\t\t\tvalue: filterValidTelemetryProps(val.value, key),\n\t\t\t\ttag: val.tag,\n\t\t\t};\n\t\t} else {\n\t\t\tprops[key] = filterValidTelemetryProps(val, key);\n\t\t}\n\t}\n\treturn props;\n}\n\n/**\n * Borrowed from\n * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#examples}\n * Avoids runtime errors with circular references.\n * Not ideal, as will cut values that are not necessarily circular references.\n * Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)\n */\n// TODO: Use `unknown` instead (API breaking change)\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const getCircularReplacer = (): ((key: string, value: unknown) => any) => {\n\tconst seen = new WeakSet();\n\treturn (key: string, value: unknown): any => {\n\t\tif (typeof value === \"object\" && value !== null) {\n\t\t\tif (seen.has(value)) {\n\t\t\t\treturn \"<removed/circular>\";\n\t\t\t}\n\t\t\tseen.add(value);\n\t\t}\n\t\treturn value;\n\t};\n};\n/* eslint-enable @typescript-eslint/no-explicit-any */\n\n/**\n * Base class for \"trusted\" errors we create, whose properties can generally be logged to telemetry safely.\n * All properties set on the object, or passed in (via the constructor or addTelemetryProperties),\n * will be logged in accordance with their tag, if present.\n *\n * PLEASE take care to avoid setting sensitive data on this object without proper tagging!\n */\nexport class LoggingError\n\textends Error\n\timplements ILoggingError, Omit<IFluidErrorBase, \"errorType\">\n{\n\tprivate _errorInstanceId = uuid();\n\tget errorInstanceId(): string {\n\t\treturn this._errorInstanceId;\n\t}\n\toverwriteErrorInstanceId(id: string): void {\n\t\tthis._errorInstanceId = id;\n\t}\n\n\t/**\n\t * Backwards compatibility to appease {@link isFluidError} in old code that may handle this error.\n\t */\n\t// @ts-expect-error - This field shouldn't be referenced in the current version, but needs to exist at runtime.\n\t// eslint-disable-next-line @typescript-eslint/prefer-as-const\n\tprivate readonly fluidErrorCode: \"-\" = \"-\";\n\n\t/**\n\t * Create a new LoggingError\n\t * @param message - Error message to use for Error base class\n\t * @param props - telemetry props to include on the error for when it's logged\n\t * @param omitPropsFromLogging - properties by name to omit from telemetry props\n\t */\n\tconstructor(\n\t\tmessage: string,\n\t\tprops?: ITelemetryProperties,\n\t\tprivate readonly omitPropsFromLogging: Set<string> = new Set(),\n\t) {\n\t\tsuper(message);\n\n\t\t// Don't log this list itself, or the private _errorInstanceId\n\t\tomitPropsFromLogging.add(\"omitPropsFromLogging\");\n\t\tomitPropsFromLogging.add(\"_errorInstanceId\");\n\n\t\tif (props) {\n\t\t\tthis.addTelemetryProperties(props);\n\t\t}\n\t}\n\n\t/**\n\t * Determines if a given object is an instance of a LoggingError\n\t * @param object - any object\n\t * @returns - true if the object is an instance of a LoggingError, false if not.\n\t */\n\tpublic static typeCheck(object: unknown): object is LoggingError {\n\t\tif (typeof object === \"object\" && object !== null) {\n\t\t\treturn (\n\t\t\t\ttypeof (object as LoggingError).addTelemetryProperties === \"function\" &&\n\t\t\t\ttypeof (object as LoggingError).getTelemetryProperties === \"function\" &&\n\t\t\t\ttypeof (object as LoggingError).errorInstanceId === \"string\"\n\t\t\t);\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Add additional properties to be logged\n\t */\n\tpublic addTelemetryProperties(props: ITelemetryProperties): void {\n\t\tcopyProps(this, props);\n\t}\n\n\t/**\n\t * Get all properties fit to be logged to telemetry for this error\n\t */\n\tpublic getTelemetryProperties(): ITelemetryProperties {\n\t\tconst taggableProps = getValidTelemetryProps(this, this.omitPropsFromLogging);\n\t\t// Include non-enumerable props that are not returned by getValidTelemetryProps\n\t\treturn {\n\t\t\t...taggableProps,\n\t\t\tstack: this.stack,\n\t\t\tmessage: this.message,\n\t\t\terrorInstanceId: this._errorInstanceId,\n\t\t};\n\t}\n}\n\n/**\n * The Error class used when normalizing an external error\n */\nexport const NORMALIZED_ERROR_TYPE = \"genericError\";\nclass NormalizedLoggingError extends LoggingError {\n\t// errorType \"genericError\" is used as a default value throughout the code.\n\t// Note that this matches ContainerErrorType/DriverErrorType's genericError\n\terrorType = NORMALIZED_ERROR_TYPE;\n\n\tconstructor(errorProps: Pick<IFluidErrorBase, \"message\" | \"stack\">) {\n\t\tsuper(errorProps.message);\n\n\t\tif (errorProps.stack !== undefined) {\n\t\t\toverwriteStack(this, errorProps.stack);\n\t\t}\n\t}\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { IEvent } from "@fluidframework/common-definitions";
5
+ import { IEvent } from "@fluidframework/core-interfaces";
6
6
  import { TypedEventEmitter, EventEmitterEventType } from "@fluidframework/common-utils";
7
7
  /**
8
8
  * Event Emitter helper class
@@ -12,6 +12,6 @@ import { TypedEventEmitter, EventEmitterEventType } from "@fluidframework/common
12
12
  export declare class EventEmitterWithErrorHandling<TEvent extends IEvent = IEvent> extends TypedEventEmitter<TEvent> {
13
13
  private readonly errorHandler;
14
14
  constructor(errorHandler: (eventName: EventEmitterEventType, error: any) => void);
15
- emit(event: EventEmitterEventType, ...args: any[]): boolean;
15
+ emit(event: EventEmitterEventType, ...args: unknown[]): boolean;
16
16
  }
17
17
  //# sourceMappingURL=eventEmitterWithErrorHandling.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"eventEmitterWithErrorHandling.d.ts","sourceRoot":"","sources":["../src/eventEmitterWithErrorHandling.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAExF;;;;GAIG;AACH,qBAAa,6BAA6B,CACzC,MAAM,SAAS,MAAM,GAAG,MAAM,CAC7B,SAAQ,iBAAiB,CAAC,MAAM,CAAC;IAEjC,OAAO,CAAC,QAAQ,CAAC,YAAY;gBAAZ,YAAY,EAAE,CAAC,SAAS,EAAE,qBAAqB,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI;IAK/E,IAAI,CAAC,KAAK,EAAE,qBAAqB,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO;CAQlE"}
1
+ {"version":3,"file":"eventEmitterWithErrorHandling.d.ts","sourceRoot":"","sources":["../src/eventEmitterWithErrorHandling.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAExF;;;;GAIG;AACH,qBAAa,6BAA6B,CACzC,MAAM,SAAS,MAAM,GAAG,MAAM,CAC7B,SAAQ,iBAAiB,CAAC,MAAM,CAAC;IAIjC,OAAO,CAAC,QAAQ,CAAC,YAAY;gBAAZ,YAAY,EAAE,CAAC,SAAS,EAAE,qBAAqB,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI;IAK/E,IAAI,CAAC,KAAK,EAAE,qBAAqB,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO;CAQtE"}
@@ -5,7 +5,10 @@ import { TypedEventEmitter } from "@fluidframework/common-utils";
5
5
  * Any exception thrown by "error" listeners will propagate to the caller.
6
6
  */
7
7
  export class EventEmitterWithErrorHandling extends TypedEventEmitter {
8
- constructor(errorHandler) {
8
+ constructor(
9
+ // TODO: use `unknown` instead (breaking API change)
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ errorHandler) {
9
12
  super();
10
13
  this.errorHandler = errorHandler;
11
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"eventEmitterWithErrorHandling.js","sourceRoot":"","sources":["../src/eventEmitterWithErrorHandling.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAyB,MAAM,8BAA8B,CAAC;AAExF;;;;GAIG;AACH,MAAM,OAAO,6BAEX,SAAQ,iBAAyB;IAClC,YACkB,YAAoE;QAErF,KAAK,EAAE,CAAC;QAFS,iBAAY,GAAZ,YAAY,CAAwD;IAGtF,CAAC;IAEM,IAAI,CAAC,KAA4B,EAAE,GAAG,IAAW;QACvD,IAAI;YACH,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;SAClC;QAAC,OAAO,KAAK,EAAE;YACf,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAChC,OAAO,IAAI,CAAC;SACZ;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { IEvent } from \"@fluidframework/common-definitions\";\nimport { TypedEventEmitter, EventEmitterEventType } from \"@fluidframework/common-utils\";\n\n/**\n * Event Emitter helper class\n * Any exceptions thrown by listeners will be caught and raised through \"error\" event.\n * Any exception thrown by \"error\" listeners will propagate to the caller.\n */\nexport class EventEmitterWithErrorHandling<\n\tTEvent extends IEvent = IEvent,\n> extends TypedEventEmitter<TEvent> {\n\tconstructor(\n\t\tprivate readonly errorHandler: (eventName: EventEmitterEventType, error: any) => void,\n\t) {\n\t\tsuper();\n\t}\n\n\tpublic emit(event: EventEmitterEventType, ...args: any[]): boolean {\n\t\ttry {\n\t\t\treturn super.emit(event, ...args);\n\t\t} catch (error) {\n\t\t\tthis.errorHandler(event, error);\n\t\t\treturn true;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"eventEmitterWithErrorHandling.js","sourceRoot":"","sources":["../src/eventEmitterWithErrorHandling.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAyB,MAAM,8BAA8B,CAAC;AAExF;;;;GAIG;AACH,MAAM,OAAO,6BAEX,SAAQ,iBAAyB;IAClC;IACC,oDAAoD;IACpD,8DAA8D;IAC7C,YAAoE;QAErF,KAAK,EAAE,CAAC;QAFS,iBAAY,GAAZ,YAAY,CAAwD;IAGtF,CAAC;IAEM,IAAI,CAAC,KAA4B,EAAE,GAAG,IAAe;QAC3D,IAAI;YACH,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;SAClC;QAAC,OAAO,KAAK,EAAE;YACf,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAChC,OAAO,IAAI,CAAC;SACZ;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { IEvent } from \"@fluidframework/core-interfaces\";\nimport { TypedEventEmitter, EventEmitterEventType } from \"@fluidframework/common-utils\";\n\n/**\n * Event Emitter helper class\n * Any exceptions thrown by listeners will be caught and raised through \"error\" event.\n * Any exception thrown by \"error\" listeners will propagate to the caller.\n */\nexport class EventEmitterWithErrorHandling<\n\tTEvent extends IEvent = IEvent,\n> extends TypedEventEmitter<TEvent> {\n\tconstructor(\n\t\t// TODO: use `unknown` instead (breaking API change)\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tprivate readonly errorHandler: (eventName: EventEmitterEventType, error: any) => void,\n\t) {\n\t\tsuper();\n\t}\n\n\tpublic emit(event: EventEmitterEventType, ...args: unknown[]): boolean {\n\t\ttry {\n\t\t\treturn super.emit(event, ...args);\n\t\t} catch (error) {\n\t\t\tthis.errorHandler(event, error);\n\t\t\treturn true;\n\t\t}\n\t}\n}\n"]}
package/lib/events.d.ts CHANGED
@@ -6,7 +6,7 @@ import { EventEmitter } from "events";
6
6
  import { ITelemetryLoggerExt } from "./telemetryTypes";
7
7
  export declare const connectedEventName = "connected";
8
8
  export declare const disconnectedEventName = "disconnected";
9
- export declare function safeRaiseEvent(emitter: EventEmitter, logger: ITelemetryLoggerExt, event: string, ...args: any[]): void;
9
+ export declare function safeRaiseEvent(emitter: EventEmitter, logger: ITelemetryLoggerExt, event: string, ...args: unknown[]): void;
10
10
  /**
11
11
  * Raises events pertaining to the connection
12
12
  * @param logger - The logger to log telemetry
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAC9C,eAAO,MAAM,qBAAqB,iBAAiB,CAAC;AAEpD,wBAAgB,cAAc,CAC7B,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,MAAM,EACb,GAAG,IAAI,OAAA,QAOP;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,YAAY,EACrB,SAAS,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,MAAM,EACjB,kBAAkB,CAAC,EAAE,MAAM,QAW3B"}
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAC9C,eAAO,MAAM,qBAAqB,iBAAiB,CAAC;AAEpD,wBAAgB,cAAc,CAC7B,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,MAAM,EACb,GAAG,IAAI,EAAE,OAAO,EAAE,GAChB,IAAI,CAMN;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,YAAY,EACrB,SAAS,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,MAAM,EACjB,kBAAkB,CAAC,EAAE,MAAM,GACzB,IAAI,CAUN"}
package/lib/events.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,CAAC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAC9C,MAAM,CAAC,MAAM,qBAAqB,GAAG,cAAc,CAAC;AAEpD,MAAM,UAAU,cAAc,CAC7B,OAAqB,EACrB,MAA2B,EAC3B,KAAa,EACb,GAAG,IAAI;IAEP,IAAI;QACH,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;KAC7B;IAAC,OAAO,KAAK,EAAE;QACf,MAAM,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;KACtE;AACF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAClC,MAA2B,EAC3B,OAAqB,EACrB,SAAkB,EAClB,QAAiB,EACjB,kBAA2B;IAE3B,IAAI;QACH,IAAI,SAAS,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;SAC3C;aAAM;YACN,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,CAAC;SACxD;KACD;IAAC,OAAO,KAAK,EAAE;QACf,MAAM,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,0BAA0B,EAAE,EAAE,KAAK,CAAC,CAAC;KACxE;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"events\";\nimport { ITelemetryLoggerExt } from \"./telemetryTypes\";\n\nexport const connectedEventName = \"connected\";\nexport const disconnectedEventName = \"disconnected\";\n\nexport function safeRaiseEvent(\n\temitter: EventEmitter,\n\tlogger: ITelemetryLoggerExt,\n\tevent: string,\n\t...args\n) {\n\ttry {\n\t\temitter.emit(event, ...args);\n\t} catch (error) {\n\t\tlogger.sendErrorEvent({ eventName: \"RaiseEventError\", event }, error);\n\t}\n}\n\n/**\n * Raises events pertaining to the connection\n * @param logger - The logger to log telemetry\n * @param emitter - The event emitter instance\n * @param connected - A boolean tracking whether the connection was in a connected state or not\n * @param clientId - The connected/disconnected clientId\n * @param disconnectedReason - The reason for the connection to be disconnected (Used for telemetry purposes only)\n */\nexport function raiseConnectedEvent(\n\tlogger: ITelemetryLoggerExt,\n\temitter: EventEmitter,\n\tconnected: boolean,\n\tclientId?: string,\n\tdisconnectedReason?: string,\n) {\n\ttry {\n\t\tif (connected) {\n\t\t\temitter.emit(connectedEventName, clientId);\n\t\t} else {\n\t\t\temitter.emit(disconnectedEventName, disconnectedReason);\n\t\t}\n\t} catch (error) {\n\t\tlogger.sendErrorEvent({ eventName: \"RaiseConnectedEventError\" }, error);\n\t}\n}\n"]}
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,CAAC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAC9C,MAAM,CAAC,MAAM,qBAAqB,GAAG,cAAc,CAAC;AAEpD,MAAM,UAAU,cAAc,CAC7B,OAAqB,EACrB,MAA2B,EAC3B,KAAa,EACb,GAAG,IAAe;IAElB,IAAI;QACH,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;KAC7B;IAAC,OAAO,KAAK,EAAE;QACf,MAAM,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;KACtE;AACF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAClC,MAA2B,EAC3B,OAAqB,EACrB,SAAkB,EAClB,QAAiB,EACjB,kBAA2B;IAE3B,IAAI;QACH,IAAI,SAAS,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;SAC3C;aAAM;YACN,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,CAAC;SACxD;KACD;IAAC,OAAO,KAAK,EAAE;QACf,MAAM,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,0BAA0B,EAAE,EAAE,KAAK,CAAC,CAAC;KACxE;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"events\";\nimport { ITelemetryLoggerExt } from \"./telemetryTypes\";\n\nexport const connectedEventName = \"connected\";\nexport const disconnectedEventName = \"disconnected\";\n\nexport function safeRaiseEvent(\n\temitter: EventEmitter,\n\tlogger: ITelemetryLoggerExt,\n\tevent: string,\n\t...args: unknown[]\n): void {\n\ttry {\n\t\temitter.emit(event, ...args);\n\t} catch (error) {\n\t\tlogger.sendErrorEvent({ eventName: \"RaiseEventError\", event }, error);\n\t}\n}\n\n/**\n * Raises events pertaining to the connection\n * @param logger - The logger to log telemetry\n * @param emitter - The event emitter instance\n * @param connected - A boolean tracking whether the connection was in a connected state or not\n * @param clientId - The connected/disconnected clientId\n * @param disconnectedReason - The reason for the connection to be disconnected (Used for telemetry purposes only)\n */\nexport function raiseConnectedEvent(\n\tlogger: ITelemetryLoggerExt,\n\temitter: EventEmitter,\n\tconnected: boolean,\n\tclientId?: string,\n\tdisconnectedReason?: string,\n): void {\n\ttry {\n\t\tif (connected) {\n\t\t\temitter.emit(connectedEventName, clientId);\n\t\t} else {\n\t\t\temitter.emit(disconnectedEventName, disconnectedReason);\n\t\t}\n\t} catch (error) {\n\t\tlogger.sendErrorEvent({ eventName: \"RaiseConnectedEventError\" }, error);\n\t}\n}\n"]}