Skip to content

Commit ff460aa

Browse files
committed
use throw new Error so errors show up in devtools
1 parent db90984 commit ff460aa

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/ts/components/extensions/notifications/NotificationContainer.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,27 @@ const NotificationContainer = (props: Props) => {
104104
const componentPath = getContextPath()
105105

106106
useEffect(() => {
107-
if (!sendNotifications || sendNotifications.length === 0) return;
107+
// Note - the type checking can be removed when it's handled properly in Dash
108+
if (sendNotifications === undefined || sendNotifications === null) return;
109+
110+
if (!Array.isArray(sendNotifications)) {
111+
throw new Error(
112+
`Expected 'sendNotifications' to be a list of dictionaries but received: ${JSON.stringify(sendNotifications)}`
113+
);
114+
return;
115+
}
108116

109117
sendNotifications.forEach((notification) => {
110118
const {action, ...realNotification} = notification;
111119

112120
// Validate action is one of the accepted values
113121
if (!allowedActions.includes(action || 'show')) {
114-
console.error(`Invalid action: '${action}' passed to action prop; should be one of '${allowedActions.join("','")}'`);
122+
throw new Error(`Invalid action: '${action}' passed to action prop; should be one of '${allowedActions.join("','")}'`);
115123
return;
116124
}
117125
if (!allowedPositions.includes(realNotification?.position || 'bottom-right')) {
118-
console.error(`Invalid position: '${realNotification?.position}' passed to position prop; should be one of '${allowedPositions.join("','")}'`);
126+
throw new Error
127+
(`Invalid position: '${realNotification?.position}' passed to position prop; should be one of '${allowedPositions.join("','")}'`);
119128
return;
120129
}
121130

@@ -132,7 +141,14 @@ const NotificationContainer = (props: Props) => {
132141
}, [sendNotifications]);
133142

134143
useEffect(() => {
135-
if (!hideNotifications || hideNotifications.length === 0) return;
144+
if (hideNotifications === undefined || hideNotifications === null) return;
145+
146+
if (!Array.isArray(hideNotifications)) {
147+
throw new Error(
148+
`Expected 'hideNotifications' to be a list of ids but received: ${JSON.stringify(hideNotifications)}`
149+
);
150+
return;
151+
}
136152

137153
hideNotifications.forEach((id) => {
138154
notifications.hide(stringifyId(id));

0 commit comments

Comments
 (0)