File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ export class LitElement extends BasicElement {
4747 */
4848export { WarningNotice } from './notices/WarningNotice.js' ;
4949export { DeprecationNotice } from './notices/DeprecationNotice.js' ;
50+ export { ErrorThrower } from './notices/ErrorThrower.js' ;
5051
5152/**
5253 * Export events
Original file line number Diff line number Diff line change 1+ export class ErrorThrower {
2+ /**
3+ * Static list to track if any error message has been shown
4+ * across the entire application session
5+ */
6+ private static readonly shownErrors = new Set < string > ( ) ;
7+
8+ /**
9+ * Checks if this error has been shown already
10+ * @param {string } message The error message to check
11+ * @returns {boolean } True if the error has been shown
12+ */
13+ public isShown ( message : string ) : boolean {
14+ return ErrorThrower . shownErrors . has ( message ) ;
15+ }
16+
17+ /**
18+ * Shows the error notice and marks it as shown
19+ * @param {string } message The error message to throw
20+ * @returns {void }
21+ */
22+ public throw ( message : string ) : void {
23+ ErrorThrower . shownErrors . add ( message ) ;
24+ throw new Error ( message ) ;
25+ }
26+
27+ /**
28+ * Shows the error notice only once per application session
29+ * @param {string } message The error message to throw
30+ * @returns {void }
31+ */
32+ public once ( message : string ) : void {
33+ if ( ! this . isShown ( message ) ) {
34+ this . throw ( message ) ;
35+ }
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { consume } from '@lit-labs/context';
33import {
44 BasicElement ,
55 CSSResultGroup ,
6+ ErrorThrower ,
67 PropertyValues ,
78 SVGTemplateResult ,
89 TemplateResult ,
@@ -30,6 +31,8 @@ const EmptyTemplate = svg``;
3031 */
3132const iconTemplateCache = new Map < string , Promise < SVGTemplateResult > > ( ) ;
3233
34+ const errorThrower = new ErrorThrower ( ) ;
35+
3336@customElement ( 'ef-icon' )
3437export class Icon extends BasicElement {
3538 /**
@@ -183,7 +186,9 @@ export class Icon extends BasicElement {
183186 } else if ( isUrl ( iconProperty ) || IconLoader . isPrefixResolved ) {
184187 void this . loadAndRenderIcon ( iconProperty ) ;
185188 } else {
186- void this . loadAndRenderSpriteIcon ( iconProperty ) ;
189+ void this . loadAndRenderSpriteIcon ( iconProperty ) . catch ( ( error ) => {
190+ errorThrower . once ( String ( error ) ) ;
191+ } ) ;
187192 }
188193 }
189194
You can’t perform that action at this time.
0 commit comments