Skip to content

Commit

Permalink
Add missing test case (and fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
markfields committed Jul 30, 2021
1 parent 3257f8f commit 2e6c9c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/utils/telemetry-utils/src/fluidErrorBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { ITelemetryProperties } from "@fluidframework/common-definitions";

/** LoggingError interface providing both a getter and setter for telemetry props */
export interface IWriteableLoggingError {
getTelemetryProperties(): ITelemetryProperties;
addTelemetryProperties: (props: ITelemetryProperties) => void;
Expand All @@ -17,7 +18,8 @@ const isIWriteableLoggingError = (x: any): x is IWriteableLoggingError =>

/**
* All normalized errors flowing through the Fluid Framework adhere to this readonly interface.
* It includes Error's properties but as optional, plus errorType and fluidErrorCode strings.
* It features errorType, fluidErrorCode, and message strings, plus Error's members as optional
* and a getter/setter for telemetry props to be included when the error is logged.
*/
export interface IFluidErrorBase extends Readonly<Partial<Error>>, IWriteableLoggingError {
readonly errorType: string;
Expand All @@ -29,7 +31,8 @@ export interface IFluidErrorBase extends Readonly<Partial<Error>>, IWriteableLog
export function isFluidError(e: any): e is IFluidErrorBase {
return typeof e?.errorType === "string" &&
typeof e?.fluidErrorCode === "string" &&
typeof e?.message === "string";
typeof e?.message === "string" &&
isIWriteableLoggingError(e);
}

/** type guard for old standard of valid/known errors */
Expand Down
12 changes: 10 additions & 2 deletions packages/utils/telemetry-utils/src/test/errorLogging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,23 @@ describe("normalizeError", () => {
stack: stackHint,
}).withExpectedTelemetryProps({ untrustedOrigin: true });
const untrustedInputs: { [label: string]: () => { input: any, expectedOutput: TestFluidError }} = {
"Fluid Error minus errorType (with stack)": () => ({
"Fluid Error minus errorType": () => ({
input: sampleFluidError().withoutProperty("errorType"),
expectedOutput: typicalOutput("Hello", "<<stack from input>>"),
}),
// "Fluid Error minus fluidErrorCode": This is a Valid Legacy Error, tested elsewhere in this file
"Fluid Error minus message (with stack)": () => ({
"Fluid Error minus message": () => ({
input: sampleFluidError().withoutProperty("message"),
expectedOutput: typicalOutput("[object Object]", "<<stack from input>>"),
}),
"Fluid Error minus getTelemetryProperties": () => ({
input: sampleFluidError().withoutProperty("getTelemetryProperties"),
expectedOutput: typicalOutput("Hello", "<<stack from input>>"),
}),
"Fluid Error minus addTelemetryProperties": () => ({
input: sampleFluidError().withoutProperty("addTelemetryProperties"),
expectedOutput: typicalOutput("Hello", "<<stack from input>>"),
}),
"Fluid Error minus errorType (no stack)": () => ({
input: sampleFluidError().withoutProperty("errorType").withoutProperty("stack"),
expectedOutput: typicalOutput("Hello", "<<generated stack>>"),
Expand Down

0 comments on commit 2e6c9c0

Please sign in to comment.