@fluidframework/telemetry-utils 2.0.0-internal.6.3.3 → 2.0.0-internal.6.4.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.
- package/CHANGELOG.md +14 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -2
- package/dist/config.js.map +1 -1
- package/dist/error.d.ts +13 -5
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +10 -2
- package/dist/error.js.map +1 -1
- package/dist/errorLogging.d.ts +36 -1
- package/dist/errorLogging.d.ts.map +1 -1
- package/dist/errorLogging.js +50 -14
- package/dist/errorLogging.js.map +1 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +15 -5
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +37 -15
- package/dist/logger.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +4 -2
- package/lib/config.js.map +1 -1
- package/lib/error.d.ts +13 -5
- package/lib/error.d.ts.map +1 -1
- package/lib/error.js +10 -2
- package/lib/error.js.map +1 -1
- package/lib/errorLogging.d.ts +36 -1
- package/lib/errorLogging.d.ts.map +1 -1
- package/lib/errorLogging.js +49 -14
- package/lib/errorLogging.js.map +1 -1
- package/lib/events.d.ts.map +1 -1
- package/lib/events.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +15 -5
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +37 -15
- package/lib/logger.js.map +1 -1
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/config.ts +4 -2
- package/src/error.ts +15 -7
- package/src/errorLogging.ts +55 -15
- package/src/events.ts +2 -0
- package/src/index.ts +1 -0
- package/src/logger.ts +68 -37
- package/src/utils.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @fluidframework/telemetry-utils
|
|
2
2
|
|
|
3
|
+
## 2.0.0-internal.6.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Upcoming: The type of the logger property/param in various APIs will be changing ([#17350](https://github.com/microsoft/FluidFramework/issues/17350)) [27284bcda3](https://github.com/microsoft/FluidFramework/commits/27284bcda3d63cc4306cf76806f8a075db0db60f)
|
|
8
|
+
|
|
9
|
+
- @fluidframework/runtime-definitions
|
|
10
|
+
- `IFluidDataStoreRuntime.logger` will be re-typed as `ITelemetryBaseLogger`
|
|
11
|
+
- @fluidframework/odsp-driver
|
|
12
|
+
- `protected OdspDocumentServiceFactoryCore.createDocumentServiceCore`'s parameter `odspLogger` will be re-typed as `ITelemetryLoggerExt`
|
|
13
|
+
- `protected LocalOdspDocumentServiceFactory.createDocumentServiceCore`'s parameter `odspLogger` will be re-typed as `ITelemetryLoggerExt`
|
|
14
|
+
|
|
15
|
+
Additionally, several of @fluidframework/telemetry-utils's exports are being marked as internal and should not be consumed outside of other FF packages.
|
|
16
|
+
|
|
3
17
|
## 2.0.0-internal.6.3.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAoB,MAAM,UAAU,CAAC;AAC/D,OAAO,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,EAAE,MAAM,CAAC,IAAI,WAAW,EAAE,MAAM,KAAK,SAAS,CAAC;AACvF,CAAC;AALD,8DAKC;AAED,SAAgB,yBAAyB,CACxC,MAAS;IAET,IAAI,yBAAyB,CAAI,MAAM,CAAC,EAAE;QACzC,OAAO,MAAM,CAAC;KACd;IACD,OAAO,sBAAsB,CAAI,MAAM,EAAE,oCAA4B,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAPD,8DAOC;AAED,SAAgB,sBAAsB,CACrC,MAAS,EACT,GAAG,OAA4C;IAE/C,IAAI,yBAAyB,CAAI,MAAM,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC1D;IACD;;;;;;;OAOG;IACH,MAAM,EAAE,GAAsC,MAAM,CAAC;IACrD,EAAE,CAAC,MAAM,GAAG,IAAI,oBAAoB,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;IACzD,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC;IACnB,OAAO,EAA0B,CAAC;AACnC,CAAC;AAnBD,wDAmBC;AAED,SAAS,oBAAoB,CAAC,GAAY;IACzC,MAAM,WAAW,GAAG,GAA+C,CAAC;IACpE,OAAO,OAAO,WAAW,EAAE,YAAY,KAAK,UAAU,CAAC;AACxD,CAAC;AAED,SAAgB,4BAA4B,CAC3C,KAA8C;IAE9C,OAAO,yBAAyB,CAAC,IAAA,0BAAiB,EAAC,KAAK,CAAC,CAAC,CAAC;AAC5D,CAAC;AAJD,oEAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { Lazy } from \"@fluidframework/core-utils\";\nimport { createChildLogger, tagCodeArtifacts } from \"./logger\";\nimport { ITelemetryLoggerExt } from \"./telemetryTypes\";\n\nexport type ConfigTypes = string | number | boolean | number[] | string[] | boolean[] | undefined;\n\n/**\n * Base interface for providing configurations to enable/disable/control features\n */\nexport interface IConfigProviderBase {\n\tgetRawConfig(name: string): ConfigTypes;\n}\n\n/**\n * Explicitly typed interface for reading configurations\n */\nexport interface IConfigProvider extends IConfigProviderBase {\n\tgetBoolean(name: string): boolean | undefined;\n\tgetNumber(name: string): number | undefined;\n\tgetString(name: string): string | undefined;\n\tgetBooleanArray(name: string): boolean[] | undefined;\n\tgetNumberArray(name: string): number[] | undefined;\n\tgetStringArray(name: string): string[] | undefined;\n}\n/**\n * Creates a base configuration provider based on `sessionStorage`\n *\n * @returns A lazy initialized base configuration provider with `sessionStorage` as the underlying config store\n */\nexport const sessionStorageConfigProvider = new Lazy<IConfigProviderBase>(() =>\n\tinMemoryConfigProvider(safeSessionStorage()),\n);\n\nconst NullConfigProvider: IConfigProviderBase = {\n\tgetRawConfig: () => undefined,\n};\n\n/**\n * Creates a base configuration provider based on the supplied `Storage` instance\n *\n * @param storage - instance of `Storage` to be used as storage media for the config\n * @returns A base configuration provider with\n * the supplied `Storage` instance as the underlying config store\n */\nexport const inMemoryConfigProvider = (storage: Storage | undefined): IConfigProviderBase => {\n\tif (storage !== undefined && storage !== null) {\n\t\treturn new CachedConfigProvider(undefined, {\n\t\t\tgetRawConfig: (name: string): ConfigTypes | undefined => {\n\t\t\t\ttry {\n\t\t\t\t\treturn stronglyTypedParse(storage.getItem(name) ?? undefined)?.raw;\n\t\t\t\t} catch {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t}\n\treturn NullConfigProvider;\n};\n\ninterface ConfigTypeStringToType {\n\tnumber: number;\n\tstring: string;\n\tboolean: boolean;\n\t[\"number[]\"]: number[];\n\t[\"string[]\"]: string[];\n\t[\"boolean[]\"]: boolean[];\n}\n\ntype PrimitiveTypeStrings = \"number\" | \"string\" | \"boolean\";\n\nfunction isPrimitiveType(type: string): type is PrimitiveTypeStrings {\n\tswitch (type) {\n\t\tcase \"boolean\":\n\t\tcase \"number\":\n\t\tcase \"string\":\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\ninterface StronglyTypedValue extends Partial<ConfigTypeStringToType> {\n\traw: ConfigTypes;\n}\n/**\n * Takes any supported config type, and returns the value with a strong type. If the type of\n * the config is not a supported type undefined will be returned.\n * The user of this function should cache the result to avoid duplicated work.\n *\n * Strings will be attempted to be parsed and coerced into a strong config type.\n * if it is not possible to parsed and coerce a string to a strong config type the original string\n * will be return with a string type for the consumer to handle further if necessary.\n */\nfunction stronglyTypedParse(input: ConfigTypes): StronglyTypedValue | undefined {\n\tlet output: ConfigTypes = input;\n\tlet defaultReturn: Pick<StronglyTypedValue, \"raw\" | \"string\"> | undefined;\n\t// we do special handling for strings to try and coerce\n\t// them into a config type if we can. This makes it easy\n\t// for config sources like sessionStorage which only\n\t// holds strings\n\tif (typeof input === \"string\") {\n\t\ttry {\n\t\t\toutput = JSON.parse(input) as ConfigTypes;\n\t\t\t// we succeeded in parsing, but we don't support parsing\n\t\t\t// for any object as we can't do it type safely\n\t\t\t// so in this case, the default return will be string\n\t\t\t// rather than undefined, and the consumer\n\t\t\t// can parse, as we don't want to provide\n\t\t\t// a false sense of security by just\n\t\t\t// casting.\n\t\t\tdefaultReturn = { raw: input, string: input };\n\t\t} catch {\n\t\t\t// No-op\n\t\t}\n\t}\n\n\tif (output === undefined) {\n\t\treturn defaultReturn;\n\t}\n\n\tconst outputType = typeof output;\n\tif (isPrimitiveType(outputType)) {\n\t\treturn { ...defaultReturn, raw: input, [outputType]: output };\n\t}\n\n\tif (Array.isArray(output)) {\n\t\tconst firstType = typeof output[0];\n\t\t// ensure the first elements is a primitive type\n\t\tif (!isPrimitiveType(firstType)) {\n\t\t\treturn defaultReturn;\n\t\t}\n\t\t// ensue all the elements types are homogeneous\n\t\t// aka they all have the same type as the first\n\t\tfor (const v of output) {\n\t\t\tif (typeof v !== firstType) {\n\t\t\t\treturn defaultReturn;\n\t\t\t}\n\t\t}\n\t\treturn { ...defaultReturn, raw: input, [`${firstType}[]`]: output };\n\t}\n\n\treturn defaultReturn;\n}\n\n/**\n * `sessionStorage` is undefined in some environments such as Node and web pages with session storage disabled.\n */\nconst safeSessionStorage = (): Storage | undefined => {\n\t// For some configurations accessing \"globalThis.sessionStorage\" throws\n\t// \"'sessionStorage' property from 'Window': Access is denied for this document\" rather than returning undefined.\n\t// Therefor check for it before accessing.\n\ttry {\n\t\t// Using globalThis and checking for undefined is preferred over just accessing global sessionStorage\n\t\t// since it avoids an exception when running in node.\n\t\t// In some cases this has returned null when disabled in the browser, so ensure its undefined in that case:\n\t\treturn globalThis.sessionStorage ?? undefined;\n\t} catch {\n\t\t// For browsers which error on the above when session storage is disabled:\n\t\treturn undefined;\n\t}\n};\n\n/**\n * Implementation of {@link IConfigProvider} which contains nested {@link IConfigProviderBase} instances\n */\nexport class CachedConfigProvider implements IConfigProvider {\n\tprivate readonly configCache = new Map<string, StronglyTypedValue>();\n\tprivate readonly orderedBaseProviders: (IConfigProviderBase | undefined)[];\n\n\tconstructor(\n\t\tprivate readonly logger?: ITelemetryBaseLogger,\n\t\t...orderedBaseProviders: (IConfigProviderBase | undefined)[]\n\t) {\n\t\tthis.orderedBaseProviders = [];\n\t\tconst knownProviders = new Set<IConfigProviderBase>();\n\t\tconst candidateProviders = [...orderedBaseProviders];\n\t\twhile (candidateProviders.length > 0) {\n\t\t\tconst baseProvider = candidateProviders.shift()!;\n\t\t\tif (\n\t\t\t\tbaseProvider !== undefined &&\n\t\t\t\tisConfigProviderBase(baseProvider) &&\n\t\t\t\t!knownProviders.has(baseProvider)\n\t\t\t) {\n\t\t\t\tknownProviders.add(baseProvider);\n\t\t\t\tif (baseProvider instanceof CachedConfigProvider) {\n\t\t\t\t\tcandidateProviders.push(...baseProvider.orderedBaseProviders);\n\t\t\t\t} else {\n\t\t\t\t\tthis.orderedBaseProviders.push(baseProvider);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tgetBoolean(name: string): boolean | undefined {\n\t\treturn this.getCacheEntry(name)?.boolean;\n\t}\n\tgetNumber(name: string): number | undefined {\n\t\treturn this.getCacheEntry(name)?.number;\n\t}\n\tgetString(name: string): string | undefined {\n\t\treturn this.getCacheEntry(name)?.string;\n\t}\n\tgetBooleanArray(name: string): boolean[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"boolean[]\"];\n\t}\n\tgetNumberArray(name: string): number[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"number[]\"];\n\t}\n\tgetStringArray(name: string): string[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"string[]\"];\n\t}\n\n\tgetRawConfig(name: string): ConfigTypes {\n\t\treturn this.getCacheEntry(name)?.raw;\n\t}\n\n\tprivate getCacheEntry(name: string): StronglyTypedValue | undefined {\n\t\tif (!this.configCache.has(name)) {\n\t\t\tfor (const provider of this.orderedBaseProviders) {\n\t\t\t\tconst parsed = stronglyTypedParse(provider?.getRawConfig(name));\n\t\t\t\tif (parsed !== undefined) {\n\t\t\t\t\tthis.configCache.set(name, parsed);\n\t\t\t\t\tthis.logger?.send({\n\t\t\t\t\t\tcategory: \"generic\",\n\t\t\t\t\t\teventName: \"ConfigRead\",\n\t\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\t\tconfigName: name,\n\t\t\t\t\t\t\tconfigValue: JSON.stringify(parsed),\n\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// configs are immutable, if the first lookup returned no results, all lookups should\n\t\t\tthis.configCache.set(name, { raw: undefined });\n\t\t}\n\t\treturn this.configCache.get(name);\n\t}\n}\n\n/**\n * A type containing both a telemetry logger and a configuration provider\n */\nexport interface MonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt> {\n\tconfig: IConfigProvider;\n\tlogger: L;\n}\n\nexport function loggerIsMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tobj: L,\n): obj is L & MonitoringContext<L> {\n\tconst maybeConfig = obj as Partial<MonitoringContext<L>> | undefined;\n\treturn isConfigProviderBase(maybeConfig?.config) && maybeConfig?.logger !== undefined;\n}\n\nexport function loggerToMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tlogger: L,\n): MonitoringContext<L> {\n\tif (loggerIsMonitoringContext<L>(logger)) {\n\t\treturn logger;\n\t}\n\treturn mixinMonitoringContext<L>(logger, sessionStorageConfigProvider.value);\n}\n\nexport function mixinMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tlogger: L,\n\t...configs: (IConfigProviderBase | undefined)[]\n): MonitoringContext<L> {\n\tif (loggerIsMonitoringContext<L>(logger)) {\n\t\tthrow new Error(\"Logger is already a monitoring context\");\n\t}\n\t/**\n\t * this is the tricky bit we use for now to smuggle monitoring context around.\n\t * To the logger we mixin both config and itself, so mc.logger === logger as it is self-referential.\n\t * We then expose it as a Monitoring context, so via types we hide the outer logger methods.\n\t * To layers that expect just a logger we can pass mc.logger, but this is still a MonitoringContext\n\t * so if a deeper layer then converts that logger to a monitoring context it can find the smuggled properties\n\t * of the MonitoringContext and get the config provider.\n\t */\n\tconst mc: L & Partial<MonitoringContext<L>> = logger;\n\tmc.config = new CachedConfigProvider(logger, ...configs);\n\tmc.logger = logger;\n\treturn mc as MonitoringContext<L>;\n}\n\nfunction isConfigProviderBase(obj: unknown): obj is IConfigProviderBase {\n\tconst maybeConfig = obj as Partial<IConfigProviderBase> | undefined;\n\treturn typeof maybeConfig?.getRawConfig === \"function\";\n}\n\nexport function createChildMonitoringContext(\n\tprops: Parameters<typeof createChildLogger>[0],\n): MonitoringContext {\n\treturn loggerToMonitoringContext(createChildLogger(props));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAKA,2DAAkD;AAClD,qCAA+D;AAuB/D;;;;GAIG;AACU,QAAA,4BAA4B,GAAG,IAAI,iBAAI,CAAsB,GAAG,EA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AAE,MAAM,CAAC,IAAI,WAAW,EAAE,MAAM,KAAK,SAAS,CAAC;AACvF,CAAC;AALD,8DAKC;AAED,SAAgB,yBAAyB,CACxC,MAAS;IAET,IAAI,yBAAyB,CAAI,MAAM,CAAC,EAAE;QACzC,OAAO,MAAM,CAAC;KACd;IACD,OAAO,sBAAsB,CAAI,MAAM,EAAE,oCAA4B,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAPD,8DAOC;AAED,SAAgB,sBAAsB,CACrC,MAAS,EACT,GAAG,OAA4C;IAE/C,IAAI,yBAAyB,CAAI,MAAM,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC1D;IACD;;;;;;;OAOG;IACH,MAAM,EAAE,GAAsC,MAAM,CAAC;IACrD,EAAE,CAAC,MAAM,GAAG,IAAI,oBAAoB,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;IACzD,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC;IACnB,OAAO,EAA0B,CAAC;AACnC,CAAC;AAnBD,wDAmBC;AAED,SAAS,oBAAoB,CAAC,GAAY;IACzC,MAAM,WAAW,GAAG,GAA+C,CAAC;IACpE,OAAO,OAAO,WAAW,EAAE,YAAY,KAAK,UAAU,CAAC;AACxD,CAAC;AAED,SAAgB,4BAA4B,CAC3C,KAA8C;IAE9C,OAAO,yBAAyB,CAAC,IAAA,0BAAiB,EAAC,KAAK,CAAC,CAAC,CAAC;AAC5D,CAAC;AAJD,oEAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { Lazy } from \"@fluidframework/core-utils\";\nimport { createChildLogger, tagCodeArtifacts } from \"./logger\";\nimport { ITelemetryLoggerExt } from \"./telemetryTypes\";\n\nexport type ConfigTypes = string | number | boolean | number[] | string[] | boolean[] | undefined;\n\n/**\n * Base interface for providing configurations to enable/disable/control features\n */\nexport interface IConfigProviderBase {\n\tgetRawConfig(name: string): ConfigTypes;\n}\n\n/**\n * Explicitly typed interface for reading configurations\n */\nexport interface IConfigProvider extends IConfigProviderBase {\n\tgetBoolean(name: string): boolean | undefined;\n\tgetNumber(name: string): number | undefined;\n\tgetString(name: string): string | undefined;\n\tgetBooleanArray(name: string): boolean[] | undefined;\n\tgetNumberArray(name: string): number[] | undefined;\n\tgetStringArray(name: string): string[] | undefined;\n}\n/**\n * Creates a base configuration provider based on `sessionStorage`\n *\n * @returns A lazy initialized base configuration provider with `sessionStorage` as the underlying config store\n */\nexport const sessionStorageConfigProvider = new Lazy<IConfigProviderBase>(() =>\n\tinMemoryConfigProvider(safeSessionStorage()),\n);\n\nconst NullConfigProvider: IConfigProviderBase = {\n\tgetRawConfig: () => undefined,\n};\n\n/**\n * Creates a base configuration provider based on the supplied `Storage` instance\n *\n * @param storage - instance of `Storage` to be used as storage media for the config\n * @returns A base configuration provider with\n * the supplied `Storage` instance as the underlying config store\n */\nexport const inMemoryConfigProvider = (storage: Storage | undefined): IConfigProviderBase => {\n\tif (storage !== undefined && storage !== null) {\n\t\treturn new CachedConfigProvider(undefined, {\n\t\t\tgetRawConfig: (name: string): ConfigTypes | undefined => {\n\t\t\t\ttry {\n\t\t\t\t\treturn stronglyTypedParse(storage.getItem(name) ?? undefined)?.raw;\n\t\t\t\t} catch {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t}\n\treturn NullConfigProvider;\n};\n\ninterface ConfigTypeStringToType {\n\tnumber: number;\n\tstring: string;\n\tboolean: boolean;\n\t[\"number[]\"]: number[];\n\t[\"string[]\"]: string[];\n\t[\"boolean[]\"]: boolean[];\n}\n\ntype PrimitiveTypeStrings = \"number\" | \"string\" | \"boolean\";\n\nfunction isPrimitiveType(type: string): type is PrimitiveTypeStrings {\n\tswitch (type) {\n\t\tcase \"boolean\":\n\t\tcase \"number\":\n\t\tcase \"string\": {\n\t\t\treturn true;\n\t\t}\n\t\tdefault: {\n\t\t\treturn false;\n\t\t}\n\t}\n}\n\ninterface StronglyTypedValue extends Partial<ConfigTypeStringToType> {\n\traw: ConfigTypes;\n}\n/**\n * Takes any supported config type, and returns the value with a strong type. If the type of\n * the config is not a supported type undefined will be returned.\n * The user of this function should cache the result to avoid duplicated work.\n *\n * Strings will be attempted to be parsed and coerced into a strong config type.\n * if it is not possible to parsed and coerce a string to a strong config type the original string\n * will be return with a string type for the consumer to handle further if necessary.\n */\nfunction stronglyTypedParse(input: ConfigTypes): StronglyTypedValue | undefined {\n\tlet output: ConfigTypes = input;\n\tlet defaultReturn: Pick<StronglyTypedValue, \"raw\" | \"string\"> | undefined;\n\t// we do special handling for strings to try and coerce\n\t// them into a config type if we can. This makes it easy\n\t// for config sources like sessionStorage which only\n\t// holds strings\n\tif (typeof input === \"string\") {\n\t\ttry {\n\t\t\toutput = JSON.parse(input) as ConfigTypes;\n\t\t\t// we succeeded in parsing, but we don't support parsing\n\t\t\t// for any object as we can't do it type safely\n\t\t\t// so in this case, the default return will be string\n\t\t\t// rather than undefined, and the consumer\n\t\t\t// can parse, as we don't want to provide\n\t\t\t// a false sense of security by just\n\t\t\t// casting.\n\t\t\tdefaultReturn = { raw: input, string: input };\n\t\t} catch {\n\t\t\t// No-op\n\t\t}\n\t}\n\n\tif (output === undefined) {\n\t\treturn defaultReturn;\n\t}\n\n\tconst outputType = typeof output;\n\tif (isPrimitiveType(outputType)) {\n\t\treturn { ...defaultReturn, raw: input, [outputType]: output };\n\t}\n\n\tif (Array.isArray(output)) {\n\t\tconst firstType = typeof output[0];\n\t\t// ensure the first elements is a primitive type\n\t\tif (!isPrimitiveType(firstType)) {\n\t\t\treturn defaultReturn;\n\t\t}\n\t\t// ensue all the elements types are homogeneous\n\t\t// aka they all have the same type as the first\n\t\tfor (const v of output) {\n\t\t\tif (typeof v !== firstType) {\n\t\t\t\treturn defaultReturn;\n\t\t\t}\n\t\t}\n\t\treturn { ...defaultReturn, raw: input, [`${firstType}[]`]: output };\n\t}\n\n\treturn defaultReturn;\n}\n\n/**\n * `sessionStorage` is undefined in some environments such as Node and web pages with session storage disabled.\n */\nconst safeSessionStorage = (): Storage | undefined => {\n\t// For some configurations accessing \"globalThis.sessionStorage\" throws\n\t// \"'sessionStorage' property from 'Window': Access is denied for this document\" rather than returning undefined.\n\t// Therefor check for it before accessing.\n\ttry {\n\t\t// Using globalThis and checking for undefined is preferred over just accessing global sessionStorage\n\t\t// since it avoids an exception when running in node.\n\t\t// In some cases this has returned null when disabled in the browser, so ensure its undefined in that case:\n\t\treturn globalThis.sessionStorage ?? undefined;\n\t} catch {\n\t\t// For browsers which error on the above when session storage is disabled:\n\t\treturn undefined;\n\t}\n};\n\n/**\n * Implementation of {@link IConfigProvider} which contains nested {@link IConfigProviderBase} instances\n */\nexport class CachedConfigProvider implements IConfigProvider {\n\tprivate readonly configCache = new Map<string, StronglyTypedValue>();\n\tprivate readonly orderedBaseProviders: (IConfigProviderBase | undefined)[];\n\n\tconstructor(\n\t\tprivate readonly logger?: ITelemetryBaseLogger,\n\t\t...orderedBaseProviders: (IConfigProviderBase | undefined)[]\n\t) {\n\t\tthis.orderedBaseProviders = [];\n\t\tconst knownProviders = new Set<IConfigProviderBase>();\n\t\tconst candidateProviders = [...orderedBaseProviders];\n\t\twhile (candidateProviders.length > 0) {\n\t\t\tconst baseProvider = candidateProviders.shift()!;\n\t\t\tif (\n\t\t\t\tbaseProvider !== undefined &&\n\t\t\t\tisConfigProviderBase(baseProvider) &&\n\t\t\t\t!knownProviders.has(baseProvider)\n\t\t\t) {\n\t\t\t\tknownProviders.add(baseProvider);\n\t\t\t\tif (baseProvider instanceof CachedConfigProvider) {\n\t\t\t\t\tcandidateProviders.push(...baseProvider.orderedBaseProviders);\n\t\t\t\t} else {\n\t\t\t\t\tthis.orderedBaseProviders.push(baseProvider);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tgetBoolean(name: string): boolean | undefined {\n\t\treturn this.getCacheEntry(name)?.boolean;\n\t}\n\tgetNumber(name: string): number | undefined {\n\t\treturn this.getCacheEntry(name)?.number;\n\t}\n\tgetString(name: string): string | undefined {\n\t\treturn this.getCacheEntry(name)?.string;\n\t}\n\tgetBooleanArray(name: string): boolean[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"boolean[]\"];\n\t}\n\tgetNumberArray(name: string): number[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"number[]\"];\n\t}\n\tgetStringArray(name: string): string[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"string[]\"];\n\t}\n\n\tgetRawConfig(name: string): ConfigTypes {\n\t\treturn this.getCacheEntry(name)?.raw;\n\t}\n\n\tprivate getCacheEntry(name: string): StronglyTypedValue | undefined {\n\t\tif (!this.configCache.has(name)) {\n\t\t\tfor (const provider of this.orderedBaseProviders) {\n\t\t\t\tconst parsed = stronglyTypedParse(provider?.getRawConfig(name));\n\t\t\t\tif (parsed !== undefined) {\n\t\t\t\t\tthis.configCache.set(name, parsed);\n\t\t\t\t\tthis.logger?.send({\n\t\t\t\t\t\tcategory: \"generic\",\n\t\t\t\t\t\teventName: \"ConfigRead\",\n\t\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\t\tconfigName: name,\n\t\t\t\t\t\t\tconfigValue: JSON.stringify(parsed),\n\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// configs are immutable, if the first lookup returned no results, all lookups should\n\t\t\tthis.configCache.set(name, { raw: undefined });\n\t\t}\n\t\treturn this.configCache.get(name);\n\t}\n}\n\n/**\n * A type containing both a telemetry logger and a configuration provider\n */\nexport interface MonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt> {\n\tconfig: IConfigProvider;\n\tlogger: L;\n}\n\nexport function loggerIsMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tobj: L,\n): obj is L & MonitoringContext<L> {\n\tconst maybeConfig = obj as Partial<MonitoringContext<L>> | undefined;\n\treturn isConfigProviderBase(maybeConfig?.config) && maybeConfig?.logger !== undefined;\n}\n\nexport function loggerToMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tlogger: L,\n): MonitoringContext<L> {\n\tif (loggerIsMonitoringContext<L>(logger)) {\n\t\treturn logger;\n\t}\n\treturn mixinMonitoringContext<L>(logger, sessionStorageConfigProvider.value);\n}\n\nexport function mixinMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tlogger: L,\n\t...configs: (IConfigProviderBase | undefined)[]\n): MonitoringContext<L> {\n\tif (loggerIsMonitoringContext<L>(logger)) {\n\t\tthrow new Error(\"Logger is already a monitoring context\");\n\t}\n\t/**\n\t * this is the tricky bit we use for now to smuggle monitoring context around.\n\t * To the logger we mixin both config and itself, so mc.logger === logger as it is self-referential.\n\t * We then expose it as a Monitoring context, so via types we hide the outer logger methods.\n\t * To layers that expect just a logger we can pass mc.logger, but this is still a MonitoringContext\n\t * so if a deeper layer then converts that logger to a monitoring context it can find the smuggled properties\n\t * of the MonitoringContext and get the config provider.\n\t */\n\tconst mc: L & Partial<MonitoringContext<L>> = logger;\n\tmc.config = new CachedConfigProvider(logger, ...configs);\n\tmc.logger = logger;\n\treturn mc as MonitoringContext<L>;\n}\n\nfunction isConfigProviderBase(obj: unknown): obj is IConfigProviderBase {\n\tconst maybeConfig = obj as Partial<IConfigProviderBase> | undefined;\n\treturn typeof maybeConfig?.getRawConfig === \"function\";\n}\n\nexport function createChildMonitoringContext(\n\tprops: Parameters<typeof createChildLogger>[0],\n): MonitoringContext {\n\treturn loggerToMonitoringContext(createChildLogger(props));\n}\n"]}
|
package/dist/error.d.ts
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { IGenericError, IErrorBase,
|
|
5
|
+
import { IGenericError, IErrorBase, ITelemetryBaseProperties, IUsageError } from "@fluidframework/core-interfaces";
|
|
6
6
|
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
7
7
|
import { LoggingError } from "./errorLogging";
|
|
8
8
|
import { IFluidErrorBase } from "./fluidErrorBase";
|
|
9
9
|
/**
|
|
10
10
|
* Generic wrapper for an unrecognized/uncategorized error object
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
11
13
|
*/
|
|
12
14
|
export declare class GenericError extends LoggingError implements IGenericError, IFluidErrorBase {
|
|
13
15
|
readonly error?: any;
|
|
@@ -18,23 +20,27 @@ export declare class GenericError extends LoggingError implements IGenericError,
|
|
|
18
20
|
* @param error - inner error object
|
|
19
21
|
* @param props - Telemetry props to include when the error is logged
|
|
20
22
|
*/
|
|
21
|
-
constructor(message: string, error?: any, props?:
|
|
23
|
+
constructor(message: string, error?: any, props?: ITelemetryBaseProperties);
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* Error indicating an API is being used improperly resulting in an invalid operation.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
25
29
|
*/
|
|
26
30
|
export declare class UsageError extends LoggingError implements IUsageError, IFluidErrorBase {
|
|
27
31
|
readonly errorType: "usageError";
|
|
28
|
-
constructor(message: string, props?:
|
|
32
|
+
constructor(message: string, props?: ITelemetryBaseProperties);
|
|
29
33
|
}
|
|
30
34
|
/**
|
|
31
35
|
* DataCorruptionError indicates that we encountered definitive evidence that the data at rest
|
|
32
36
|
* backing this container is corrupted, and this container would never be expected to load properly again
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
33
39
|
*/
|
|
34
40
|
export declare class DataCorruptionError extends LoggingError implements IErrorBase, IFluidErrorBase {
|
|
35
41
|
readonly errorType: "dataCorruptionError";
|
|
36
42
|
readonly canRetry = false;
|
|
37
|
-
constructor(message: string, props:
|
|
43
|
+
constructor(message: string, props: ITelemetryBaseProperties);
|
|
38
44
|
}
|
|
39
45
|
/**
|
|
40
46
|
* Indicates we hit a fatal error while processing incoming data from the Fluid Service.
|
|
@@ -44,6 +50,8 @@ export declare class DataCorruptionError extends LoggingError implements IErrorB
|
|
|
44
50
|
* The error will often originate in the dataStore or DDS implementation that is responding to incoming changes.
|
|
45
51
|
* This differs from {@link DataCorruptionError} in that this may be a transient error that will not repro in another
|
|
46
52
|
* client or session.
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
47
55
|
*/
|
|
48
56
|
export declare class DataProcessingError extends LoggingError implements IErrorBase, IFluidErrorBase {
|
|
49
57
|
/**
|
|
@@ -55,7 +63,7 @@ export declare class DataProcessingError extends LoggingError implements IErrorB
|
|
|
55
63
|
/**
|
|
56
64
|
* Create a new `DataProcessingError` detected and raised within the Fluid Framework.
|
|
57
65
|
*/
|
|
58
|
-
static create(errorMessage: string, dataProcessingCodepath: string, sequencedMessage?: ISequencedDocumentMessage, props?:
|
|
66
|
+
static create(errorMessage: string, dataProcessingCodepath: string, sequencedMessage?: ISequencedDocumentMessage, props?: ITelemetryBaseProperties): IFluidErrorBase;
|
|
59
67
|
/**
|
|
60
68
|
* Wrap the given error in a `DataProcessingError`, unless the error is already of a known type
|
|
61
69
|
* with the exception of a normalized {@link LoggingError}, which will still be wrapped.
|
package/dist/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEN,aAAa,EACb,UAAU,EACV,
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEN,aAAa,EACb,UAAU,EACV,wBAAwB,EACxB,WAAW,EACX,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAEjF,OAAO,EACN,YAAY,EAKZ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ACC,eAAe;CA6BlB;AAED;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,gBAC/B,QACZ,KACC,yBAAyB,EACvB,UAAU,GACV,gBAAgB,GAChB,sBAAsB,GACtB,yBAAyB,GACzB,uBAAuB,GACvB,WAAW,CACb,CACD,KACC;IACF,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,qBAAqB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,2BAA2B,EAAE,MAAM,GAAG,SAAS,CAAC;IAChD,8BAA8B,EAAE,MAAM,GAAG,SAAS,CAAC;IACnD,4BAA4B,EAAE,MAAM,GAAG,SAAS,CAAC;IACjD,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;CAQpC,CAAC"}
|
package/dist/error.js
CHANGED
|
@@ -9,6 +9,8 @@ const core_interfaces_1 = require("@fluidframework/core-interfaces");
|
|
|
9
9
|
const errorLogging_1 = require("./errorLogging");
|
|
10
10
|
/**
|
|
11
11
|
* Generic wrapper for an unrecognized/uncategorized error object
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
12
14
|
*/
|
|
13
15
|
class GenericError extends errorLogging_1.LoggingError {
|
|
14
16
|
/**
|
|
@@ -29,6 +31,8 @@ class GenericError extends errorLogging_1.LoggingError {
|
|
|
29
31
|
exports.GenericError = GenericError;
|
|
30
32
|
/**
|
|
31
33
|
* Error indicating an API is being used improperly resulting in an invalid operation.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
32
36
|
*/
|
|
33
37
|
class UsageError extends errorLogging_1.LoggingError {
|
|
34
38
|
constructor(message, props) {
|
|
@@ -40,6 +44,8 @@ exports.UsageError = UsageError;
|
|
|
40
44
|
/**
|
|
41
45
|
* DataCorruptionError indicates that we encountered definitive evidence that the data at rest
|
|
42
46
|
* backing this container is corrupted, and this container would never be expected to load properly again
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
43
49
|
*/
|
|
44
50
|
class DataCorruptionError extends errorLogging_1.LoggingError {
|
|
45
51
|
constructor(message, props) {
|
|
@@ -57,10 +63,12 @@ exports.DataCorruptionError = DataCorruptionError;
|
|
|
57
63
|
* The error will often originate in the dataStore or DDS implementation that is responding to incoming changes.
|
|
58
64
|
* This differs from {@link DataCorruptionError} in that this may be a transient error that will not repro in another
|
|
59
65
|
* client or session.
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
60
68
|
*/
|
|
61
69
|
class DataProcessingError extends errorLogging_1.LoggingError {
|
|
62
|
-
constructor(errorMessage) {
|
|
63
|
-
super(errorMessage);
|
|
70
|
+
constructor(errorMessage, props) {
|
|
71
|
+
super(errorMessage, props);
|
|
64
72
|
/**
|
|
65
73
|
* {@inheritDoc IFluidErrorBase.errorType}
|
|
66
74
|
*/
|
package/dist/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qEAMyC;AAGzC,iDAMwB;AAGxB
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qEAMyC;AAGzC,iDAMwB;AAGxB;;;;GAIG;AACH,MAAa,YAAa,SAAQ,2BAAY;IAG7C;;;;;OAKG;IACH,mIAAmI;IACnI,iHAAiH;IACjH,YAAY,OAAe,EAAkB,KAAW,EAAE,KAAgC;QACzF,mCAAmC;QACnC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAFE,UAAK,GAAL,KAAK,CAAM;QAV/C,cAAS,GAAG,iCAAe,CAAC,YAAY,CAAC;IAalD,CAAC;CACD;AAfD,oCAeC;AAED;;;;GAIG;AACH,MAAa,UAAW,SAAQ,2BAAY;IAG3C,YAAY,OAAe,EAAE,KAAgC;QAC5D,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,KAAK,EAAE,UAAU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,eAAe,GAAG,IAAA,6BAAc,EAAC,aAAa,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACjE,uEAAuE;QACvE,0EAA0E;QAC1E,IACC,IAAA,8BAAe,EAAC,eAAe,CAAC;YAChC,eAAe,CAAC,SAAS,KAAK,oCAAqB,EAClD;YACD,+DAA+D;YAC/D,MAAM,mBAAmB,GAAG,IAAA,wBAAS,EACpC,eAAe,EACf,CAAC,OAAe,EAAE,EAAE,CAAC,IAAI,mBAAmB,CAAC,OAAO,CAAC,CACrD,CAAC;YAEF,4FAA4F;YAC5F,mBAAmB,CAAC,sBAAsB,CAAC,eAAe,CAAC,sBAAsB,EAAE,CAAC,CAAC;YAErF,OAAO,mBAAmB,CAAC;SAC3B;QACD,OAAO,eAAe,CAAC;IACxB,CAAC;CACD;AA5FD,kDA4FC;AAED;;;;GAIG;AACI,MAAM,gCAAgC,GAAG,CAC/C,WAUC,EAQA,EAAE,CAAC,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;AA1BU,QAAA,gCAAgC,oCA0B1C","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\tITelemetryBaseProperties,\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 *\n * @internal\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?: ITelemetryBaseProperties) {\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 *\n * @internal\n */\nexport class UsageError extends LoggingError implements IUsageError, IFluidErrorBase {\n\treadonly errorType = FluidErrorTypes.usageError;\n\n\tconstructor(message: string, props?: ITelemetryBaseProperties) {\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 *\n * @internal\n */\nexport class DataCorruptionError extends LoggingError implements IErrorBase, IFluidErrorBase {\n\treadonly errorType = FluidErrorTypes.dataCorruptionError;\n\treadonly canRetry = false;\n\n\tconstructor(message: string, props: ITelemetryBaseProperties) {\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 *\n * @internal\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, props?: ITelemetryBaseProperties) {\n\t\tsuper(errorMessage, props);\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: ITelemetryBaseProperties = {},\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"]}
|
package/dist/errorLogging.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ import { IFluidErrorBase } from "./fluidErrorBase";
|
|
|
7
7
|
import { ITelemetryLoggerExt, TelemetryEventPropertyTypeExt } from "./telemetryTypes";
|
|
8
8
|
/**
|
|
9
9
|
* Inspect the given error for common "safe" props and return them.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
10
12
|
*/
|
|
11
13
|
export declare function extractLogSafeErrorProperties(error: unknown, sanitizeStack: boolean): {
|
|
12
14
|
message: string;
|
|
@@ -19,6 +21,8 @@ export declare function extractLogSafeErrorProperties(error: unknown, sanitizeSt
|
|
|
19
21
|
export declare const isILoggingError: (x: unknown) => x is ILoggingError;
|
|
20
22
|
/**
|
|
21
23
|
* Metadata to annotate an error object when annotating or normalizing it
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
22
26
|
*/
|
|
23
27
|
export interface IFluidErrorAnnotations {
|
|
24
28
|
/**
|
|
@@ -31,6 +35,8 @@ export interface IFluidErrorAnnotations {
|
|
|
31
35
|
* @returns A valid Fluid Error with any provided annotations applied
|
|
32
36
|
* @param error - The error to normalize
|
|
33
37
|
* @param annotations - Annotations to apply to the normalized error
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
34
40
|
*/
|
|
35
41
|
export declare function normalizeError(error: unknown, annotations?: IFluidErrorAnnotations): IFluidErrorBase;
|
|
36
42
|
/**
|
|
@@ -41,8 +47,16 @@ export declare function normalizeError(error: unknown, annotations?: IFluidError
|
|
|
41
47
|
* For such cases it's better to not read stack property right away, but rather delay it until / if it's needed
|
|
42
48
|
* Some browsers will populate stack right away, others require throwing Error, so we do auto-detection on the fly.
|
|
43
49
|
* @returns Error object that has stack populated.
|
|
50
|
+
*
|
|
51
|
+
* @internal
|
|
44
52
|
*/
|
|
45
53
|
export declare function generateErrorWithStack(): Error;
|
|
54
|
+
/**
|
|
55
|
+
* Generate a stack at this callsite as if an error were thrown from here.
|
|
56
|
+
* @returns the callstack (does not throw)
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
46
60
|
export declare function generateStack(): string | undefined;
|
|
47
61
|
/**
|
|
48
62
|
* Create a new error using newErrorFn, wrapping and caused by the given unknown error.
|
|
@@ -50,18 +64,33 @@ export declare function generateStack(): string | undefined;
|
|
|
50
64
|
* @param innerError - An error from untrusted/unknown origins
|
|
51
65
|
* @param newErrorFn - callback that will create a new error given the original error's message
|
|
52
66
|
* @returns A new error object "wrapping" the given error
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
53
69
|
*/
|
|
54
70
|
export declare function wrapError<T extends LoggingError>(innerError: unknown, newErrorFn: (message: string) => T): T;
|
|
55
71
|
/**
|
|
56
72
|
* The same as wrapError, but also logs the innerError, including the wrapping error's instance ID.
|
|
57
73
|
*
|
|
58
74
|
* @typeParam T - The kind of wrapper error to create.
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
59
77
|
*/
|
|
60
78
|
export declare function wrapErrorAndLog<T extends LoggingError>(innerError: unknown, newErrorFn: (message: string) => T, logger: ITelemetryLoggerExt): T;
|
|
79
|
+
/**
|
|
80
|
+
* Attempts to overwrite the error's stack
|
|
81
|
+
*
|
|
82
|
+
* There have been reports of certain JS environments where overwriting stack will throw.
|
|
83
|
+
* If that happens, this adds the given stack as the telemetry property "stack2"
|
|
84
|
+
*
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
export declare function overwriteStack(error: IFluidErrorBase | LoggingError, stack: string): void;
|
|
61
88
|
/**
|
|
62
89
|
* True for any error object that is an (optionally normalized) external error
|
|
63
90
|
* False for any error we created and raised within the FF codebase via LoggingError base class,
|
|
64
91
|
* or wrapped in a well-known error type
|
|
92
|
+
*
|
|
93
|
+
* @internal
|
|
65
94
|
*/
|
|
66
95
|
export declare function isExternalError(error: unknown): boolean;
|
|
67
96
|
/**
|
|
@@ -74,6 +103,8 @@ export declare function isTaggedTelemetryPropertyValue(x: Tagged<TelemetryEventP
|
|
|
74
103
|
* Avoids runtime errors with circular references.
|
|
75
104
|
* Not ideal, as will cut values that are not necessarily circular references.
|
|
76
105
|
* Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)
|
|
106
|
+
*
|
|
107
|
+
* @internal
|
|
77
108
|
*/
|
|
78
109
|
export declare const getCircularReplacer: () => (key: string, value: unknown) => any;
|
|
79
110
|
/**
|
|
@@ -82,6 +113,8 @@ export declare const getCircularReplacer: () => (key: string, value: unknown) =>
|
|
|
82
113
|
* will be logged in accordance with their tag, if present.
|
|
83
114
|
*
|
|
84
115
|
* PLEASE take care to avoid setting sensitive data on this object without proper tagging!
|
|
116
|
+
*
|
|
117
|
+
* @internal
|
|
85
118
|
*/
|
|
86
119
|
export declare class LoggingError extends Error implements ILoggingError, Omit<IFluidErrorBase, "errorType"> {
|
|
87
120
|
private readonly omitPropsFromLogging;
|
|
@@ -102,7 +135,7 @@ export declare class LoggingError extends Error implements ILoggingError, Omit<I
|
|
|
102
135
|
/**
|
|
103
136
|
* Determines if a given object is an instance of a LoggingError
|
|
104
137
|
* @param object - any object
|
|
105
|
-
* @returns
|
|
138
|
+
* @returns true if the object is an instance of a LoggingError, false if not.
|
|
106
139
|
*/
|
|
107
140
|
static typeCheck(object: unknown): object is LoggingError;
|
|
108
141
|
/**
|
|
@@ -116,6 +149,8 @@ export declare class LoggingError extends Error implements ILoggingError, Omit<I
|
|
|
116
149
|
}
|
|
117
150
|
/**
|
|
118
151
|
* The Error class used when normalizing an external error
|
|
152
|
+
*
|
|
153
|
+
* @internal
|
|
119
154
|
*/
|
|
120
155
|
export declare const NORMALIZED_ERROR_TYPE = "genericError";
|
|
121
156
|
//# 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,wBAAwB,EAExB,MAAM,EACN,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAEN,eAAe,EAGf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AAStF
|
|
1
|
+
{"version":3,"file":"errorLogging.d.ts","sourceRoot":"","sources":["../src/errorLogging.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,aAAa,EACb,wBAAwB,EAExB,MAAM,EACN,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAEN,eAAe,EAGf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AAStF;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC5C,KAAK,EAAE,OAAO,EACd,aAAa,EAAE,OAAO,GACpB;IACF,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B,CAoCA;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,MAAO,OAAO,uBACkC,CAAC;AAgB7E;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,KAAK,CAAC,EAAE,wBAAwB,CAAC;CACjC;AAeD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,OAAO,EACd,WAAW,GAAE,sBAA2B,GACtC,eAAe,CAqDjB;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,IAAI,KAAK,CAgB9C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,MAAM,GAAG,SAAS,CAElD;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,YAAY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AAY;IAWhE;;OAEG;IACI,sBAAsB,CAAC,KAAK,EAAE,wBAAwB,GAAG,IAAI;IAIpE;;OAEG;IACI,sBAAsB,IAAI,wBAAwB;CAUzD;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,iBAAiB,CAAC"}
|
package/dist/errorLogging.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.NORMALIZED_ERROR_TYPE = exports.LoggingError = exports.getCircularReplacer = exports.isTaggedTelemetryPropertyValue = exports.isExternalError = exports.wrapErrorAndLog = exports.wrapError = exports.generateStack = exports.generateErrorWithStack = exports.normalizeError = exports.isILoggingError = exports.extractLogSafeErrorProperties = void 0;
|
|
7
|
+
exports.NORMALIZED_ERROR_TYPE = exports.LoggingError = exports.getCircularReplacer = exports.isTaggedTelemetryPropertyValue = exports.isExternalError = exports.overwriteStack = exports.wrapErrorAndLog = exports.wrapError = exports.generateStack = exports.generateErrorWithStack = exports.normalizeError = exports.isILoggingError = exports.extractLogSafeErrorProperties = void 0;
|
|
8
8
|
const uuid_1 = require("uuid");
|
|
9
9
|
const fluidErrorBase_1 = require("./fluidErrorBase");
|
|
10
10
|
/**
|
|
@@ -15,6 +15,8 @@ const isRegularObject = (value) => {
|
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Inspect the given error for common "safe" props and return them.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
18
20
|
*/
|
|
19
21
|
function extractLogSafeErrorProperties(error, sanitizeStack) {
|
|
20
22
|
const removeMessageFromStack = (stack, errorName) => {
|
|
@@ -77,6 +79,8 @@ function patchLegacyError(legacyError) {
|
|
|
77
79
|
* @returns A valid Fluid Error with any provided annotations applied
|
|
78
80
|
* @param error - The error to normalize
|
|
79
81
|
* @param annotations - Annotations to apply to the normalized error
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
80
84
|
*/
|
|
81
85
|
function normalizeError(error, annotations = {}) {
|
|
82
86
|
// Back-compat, while IFluidErrorBase is rolled out
|
|
@@ -135,6 +139,8 @@ let stackPopulatedOnCreation;
|
|
|
135
139
|
* For such cases it's better to not read stack property right away, but rather delay it until / if it's needed
|
|
136
140
|
* Some browsers will populate stack right away, others require throwing Error, so we do auto-detection on the fly.
|
|
137
141
|
* @returns Error object that has stack populated.
|
|
142
|
+
*
|
|
143
|
+
* @internal
|
|
138
144
|
*/
|
|
139
145
|
function generateErrorWithStack() {
|
|
140
146
|
const err = new Error("<<generated stack>>");
|
|
@@ -152,6 +158,12 @@ function generateErrorWithStack() {
|
|
|
152
158
|
}
|
|
153
159
|
}
|
|
154
160
|
exports.generateErrorWithStack = generateErrorWithStack;
|
|
161
|
+
/**
|
|
162
|
+
* Generate a stack at this callsite as if an error were thrown from here.
|
|
163
|
+
* @returns the callstack (does not throw)
|
|
164
|
+
*
|
|
165
|
+
* @internal
|
|
166
|
+
*/
|
|
155
167
|
function generateStack() {
|
|
156
168
|
return generateErrorWithStack().stack;
|
|
157
169
|
}
|
|
@@ -162,6 +174,8 @@ exports.generateStack = generateStack;
|
|
|
162
174
|
* @param innerError - An error from untrusted/unknown origins
|
|
163
175
|
* @param newErrorFn - callback that will create a new error given the original error's message
|
|
164
176
|
* @returns A new error object "wrapping" the given error
|
|
177
|
+
*
|
|
178
|
+
* @internal
|
|
165
179
|
*/
|
|
166
180
|
function wrapError(innerError, newErrorFn) {
|
|
167
181
|
const { message, stack } = extractLogSafeErrorProperties(innerError, false /* sanitizeStack */);
|
|
@@ -191,6 +205,8 @@ exports.wrapError = wrapError;
|
|
|
191
205
|
* The same as wrapError, but also logs the innerError, including the wrapping error's instance ID.
|
|
192
206
|
*
|
|
193
207
|
* @typeParam T - The kind of wrapper error to create.
|
|
208
|
+
*
|
|
209
|
+
* @internal
|
|
194
210
|
*/
|
|
195
211
|
function wrapErrorAndLog(innerError, newErrorFn, logger) {
|
|
196
212
|
const newError = wrapError(innerError, newErrorFn);
|
|
@@ -206,8 +222,15 @@ function wrapErrorAndLog(innerError, newErrorFn, logger) {
|
|
|
206
222
|
return newError;
|
|
207
223
|
}
|
|
208
224
|
exports.wrapErrorAndLog = wrapErrorAndLog;
|
|
225
|
+
/**
|
|
226
|
+
* Attempts to overwrite the error's stack
|
|
227
|
+
*
|
|
228
|
+
* There have been reports of certain JS environments where overwriting stack will throw.
|
|
229
|
+
* If that happens, this adds the given stack as the telemetry property "stack2"
|
|
230
|
+
*
|
|
231
|
+
* @internal
|
|
232
|
+
*/
|
|
209
233
|
function overwriteStack(error, stack) {
|
|
210
|
-
// supposedly setting stack on an Error can throw.
|
|
211
234
|
try {
|
|
212
235
|
Object.assign(error, { stack });
|
|
213
236
|
}
|
|
@@ -215,10 +238,13 @@ function overwriteStack(error, stack) {
|
|
|
215
238
|
error.addTelemetryProperties({ stack2: stack });
|
|
216
239
|
}
|
|
217
240
|
}
|
|
241
|
+
exports.overwriteStack = overwriteStack;
|
|
218
242
|
/**
|
|
219
243
|
* True for any error object that is an (optionally normalized) external error
|
|
220
244
|
* False for any error we created and raised within the FF codebase via LoggingError base class,
|
|
221
245
|
* or wrapped in a well-known error type
|
|
246
|
+
*
|
|
247
|
+
* @internal
|
|
222
248
|
*/
|
|
223
249
|
function isExternalError(error) {
|
|
224
250
|
// LoggingErrors are an internal FF error type. However, an external error can be converted
|
|
@@ -242,8 +268,8 @@ function isTaggedTelemetryPropertyValue(x) {
|
|
|
242
268
|
exports.isTaggedTelemetryPropertyValue = isTaggedTelemetryPropertyValue;
|
|
243
269
|
/**
|
|
244
270
|
* Filter serializable telemetry properties
|
|
245
|
-
* @param x -
|
|
246
|
-
* @returns -
|
|
271
|
+
* @param x - Any telemetry prop
|
|
272
|
+
* @returns As-is if x is primitive. returns stringified if x is an array of primitive.
|
|
247
273
|
* otherwise returns null since this is what we support at the moment.
|
|
248
274
|
*/
|
|
249
275
|
function filterValidTelemetryProps(x, key) {
|
|
@@ -263,10 +289,12 @@ function isTelemetryEventPropertyValue(x) {
|
|
|
263
289
|
case "string":
|
|
264
290
|
case "number":
|
|
265
291
|
case "boolean":
|
|
266
|
-
case "undefined":
|
|
292
|
+
case "undefined": {
|
|
267
293
|
return true;
|
|
268
|
-
|
|
294
|
+
}
|
|
295
|
+
default: {
|
|
269
296
|
return false;
|
|
297
|
+
}
|
|
270
298
|
}
|
|
271
299
|
}
|
|
272
300
|
/**
|
|
@@ -280,15 +308,12 @@ function getValidTelemetryProps(obj, keysToOmit) {
|
|
|
280
308
|
}
|
|
281
309
|
const val = obj[key];
|
|
282
310
|
// ensure only valid props get logged, since props of logging error could be in any shape
|
|
283
|
-
|
|
284
|
-
|
|
311
|
+
props[key] = isTaggedTelemetryPropertyValue(val)
|
|
312
|
+
? {
|
|
285
313
|
value: filterValidTelemetryProps(val.value, key),
|
|
286
314
|
tag: val.tag,
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
else {
|
|
290
|
-
props[key] = filterValidTelemetryProps(val, key);
|
|
291
|
-
}
|
|
315
|
+
}
|
|
316
|
+
: filterValidTelemetryProps(val, key);
|
|
292
317
|
}
|
|
293
318
|
return props;
|
|
294
319
|
}
|
|
@@ -298,6 +323,8 @@ function getValidTelemetryProps(obj, keysToOmit) {
|
|
|
298
323
|
* Avoids runtime errors with circular references.
|
|
299
324
|
* Not ideal, as will cut values that are not necessarily circular references.
|
|
300
325
|
* Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)
|
|
326
|
+
*
|
|
327
|
+
* @internal
|
|
301
328
|
*/
|
|
302
329
|
// TODO: Use `unknown` instead (API breaking change)
|
|
303
330
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
@@ -321,6 +348,8 @@ exports.getCircularReplacer = getCircularReplacer;
|
|
|
321
348
|
* will be logged in accordance with their tag, if present.
|
|
322
349
|
*
|
|
323
350
|
* PLEASE take care to avoid setting sensitive data on this object without proper tagging!
|
|
351
|
+
*
|
|
352
|
+
* @internal
|
|
324
353
|
*/
|
|
325
354
|
class LoggingError extends Error {
|
|
326
355
|
/**
|
|
@@ -355,7 +384,7 @@ class LoggingError extends Error {
|
|
|
355
384
|
/**
|
|
356
385
|
* Determines if a given object is an instance of a LoggingError
|
|
357
386
|
* @param object - any object
|
|
358
|
-
* @returns
|
|
387
|
+
* @returns true if the object is an instance of a LoggingError, false if not.
|
|
359
388
|
*/
|
|
360
389
|
static typeCheck(object) {
|
|
361
390
|
if (typeof object === "object" && object !== null) {
|
|
@@ -388,8 +417,15 @@ class LoggingError extends Error {
|
|
|
388
417
|
exports.LoggingError = LoggingError;
|
|
389
418
|
/**
|
|
390
419
|
* The Error class used when normalizing an external error
|
|
420
|
+
*
|
|
421
|
+
* @internal
|
|
391
422
|
*/
|
|
392
423
|
exports.NORMALIZED_ERROR_TYPE = "genericError";
|
|
424
|
+
/**
|
|
425
|
+
* Subclass of LoggingError returned by normalizeError
|
|
426
|
+
*
|
|
427
|
+
* @internal
|
|
428
|
+
*/
|
|
393
429
|
class NormalizedLoggingError extends LoggingError {
|
|
394
430
|
constructor(errorProps) {
|
|
395
431
|
super(errorProps.message);
|