-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add warn/error message infrastructure (#5776)
* feat: add warn/error message infrastructure * Change files * feat: add sideEffects files and basic debug tests Co-authored-by: EisenbergEffect <[email protected]>
- Loading branch information
1 parent
da2af7e
commit d57a864
Showing
13 changed files
with
144 additions
and
20 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@microsoft-fast-element-07e66f75-3b9f-4287-b48c-3151388366f4.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "feat: add warn/error message infrastructure", | ||
"packageName": "@microsoft/fast-element", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { expect } from "chai"; | ||
import "./debug.js"; | ||
import { FASTGlobal, Message } from "./interfaces"; | ||
|
||
declare const FAST: FASTGlobal; | ||
|
||
describe("The debug module", () => { | ||
context("when sending errors", () => { | ||
it("expect known error message from known error code", () => { | ||
const error = FAST.error(Message.bindingInnerHTMLRequiresTrustedTypes); | ||
expect(error.message.length).greaterThan(0); | ||
expect(error.message).not.equal("Unknown Error"); | ||
}); | ||
|
||
it("expect unknown error message from unknown error code", () => { | ||
const error = FAST.error(10); | ||
expect(error.message).equal("Unknown Error"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { FASTGlobal } from "./interfaces.js"; | ||
|
||
if (globalThis.FAST === void 0) { | ||
Reflect.defineProperty(globalThis, "FAST", { | ||
value: Object.create(null), | ||
configurable: false, | ||
enumerable: false, | ||
writable: false, | ||
}); | ||
} | ||
|
||
const FAST: FASTGlobal = globalThis.FAST; | ||
|
||
const debugMessages = { | ||
[1101 /* needsArrayObservation */]: "Must call enableArrayObservation before observing arrays.", | ||
[1201 /* onlySetHTMLPolicyOnce */]: "The HTML policy can only be set once.", | ||
[1202 /* bindingInnerHTMLRequiresTrustedTypes */]: "To bind innerHTML, you must use a TrustedTypesPolicy.", | ||
[1401 /* missingElementDefinition */]: "Missing FASTElement definition.", | ||
}; | ||
|
||
Object.assign(FAST, { | ||
addMessages(messages: Record<number, string>) { | ||
Object.assign(debugMessages, messages); | ||
}, | ||
warn(code: number, ...args: any[]) { | ||
console.warn(debugMessages[code] ?? "Unknown Warning"); | ||
}, | ||
error(code: number, ...args: any[]) { | ||
return new Error(debugMessages[code] ?? "Unknown Error"); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters