Skip to content

Commit 6f752d7

Browse files
committed
fix(notifications): icons causing runtime error
Problem: Making the icon red for emergency notifications requires changing the color property. To do it in 1 line we use a ternary statement and unwrap. This causes runtime error similar to: `cannot access property of undefined: 0`. Solution: Use object.assign instead
1 parent c6e31ff commit 6f752d7

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/core/src/notifications/panelNode.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as vscode from 'vscode'
77
import { ResourceTreeDataProvider, TreeNode } from '../shared/treeview/resourceTreeDataProvider'
88
import { Command, Commands } from '../shared/vscode/commands2'
9-
import { Icon, IconPath, getIcon } from '../shared/icons'
9+
import { Icon, getIcon } from '../shared/icons'
1010
import { contextKey, setContext } from '../shared/vscode/setContext'
1111
import { NotificationType, OnReceiveType, ToolkitNotification, getNotificationTelemetryId } from './types'
1212
import { ToolkitError } from '../shared/errors'
@@ -81,10 +81,13 @@ export class NotificationsNode implements TreeNode {
8181

8282
public getChildren() {
8383
const buildNode = (n: ToolkitNotification, type: NotificationType) => {
84-
const icon: Icon | IconPath =
85-
type === 'startUp'
86-
? getIcon('vscode-question')
87-
: { ...getIcon('vscode-alert'), color: new vscode.ThemeColor('errorForeground') }
84+
const icon: Icon =
85+
type === 'emergency'
86+
? Object.assign(getIcon('vscode-alert') as Icon, {
87+
color: new vscode.ThemeColor('errorForeground'),
88+
})
89+
: (getIcon('vscode-question') as Icon)
90+
8891
return this.openNotificationCmd.build(n).asTreeNode({
8992
label: n.uiRenderInstructions.content['en-US'].title,
9093
iconPath: icon,

0 commit comments

Comments
 (0)