Skip to content

Commit

Permalink
Safety check all calls to .map for null arrays, see vscode-server-con…
Browse files Browse the repository at this point in the history
…nector/issues/557

Signed-off-by: Rob Stryker <[email protected]>
  • Loading branch information
robstryker committed Nov 7, 2022
1 parent 14f1962 commit 5c8a74c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/extensionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ export class CommandHandler {
server.publishState === ServerState.PUBLISH_STATE_UNKNOWN;
const serverId = await this.selectServer(rsp.id, 'Select server to remove deployment from', serverFilter);
if (!serverId) return null;
const deployables = this.explorer.getServerStateById(rsp.id, serverId).deployableStates.map(value => {
const state: ServerStateNode | undefined = this.explorer.getServerStateById(rsp.id, serverId);
const deployableStates: DeployableStateNode[] = (!state || !state.deployableStates) ? [] : state.deployableStates;
const deployables = deployableStates.map(value => {
return {
label: value.reference.label,
deployable: value
Expand Down Expand Up @@ -574,7 +576,8 @@ export class CommandHandler {
private async chooseServerActions(server: Protocol.ServerHandle, client: RSPClient): Promise<ServerActionItem> {
const actionsList: ServerActionItem[] = await client.getOutgoingHandler().listServerActions(server)
.then((response: Protocol.ListServerActionResponse) => {
return response.workflows.map(action => {
const entries = (!response || !response.workflows) ? [] : response.workflows;
return entries.map(action => {
return {
label: action.actionLabel,
id: action.actionId,
Expand Down Expand Up @@ -730,7 +733,7 @@ export class CommandHandler {
private async selectRSP(message: string, predicateFilter?: (value: RSPProperties) => unknown): Promise<{ label: string; id: string; }> {
const vals = Array.from(this.explorer.RSPServersStatus.values());
const predicateFilter2 = predicateFilter ? predicateFilter : value => value.state.state === ServerState.STARTED;
const rspProviders = vals.filter(predicateFilter2).map(rsp => {
const rspProviders = (vals.filter(predicateFilter2) || []).map(rsp => {
return {
label: (!rsp.state.type.visibilename ?
rsp.state.type.id :
Expand Down Expand Up @@ -796,7 +799,7 @@ export class CommandHandler {

private async promptDownloadableRuntimes(client: RSPClient): Promise<string> {
const fromRsp: Protocol.ListDownloadRuntimeResponse = await client.getOutgoingHandler().listDownloadableRuntimes(CommandHandler.LIST_RUNTIMES_TIMEOUT);
const runtimes = fromRsp.runtimes;
const runtimes = fromRsp.runtimes || [];
const uniquePrefixes = [];
for(let i = 0; i < runtimes.length; i++) {
const numInd = runtimes[i].name.search(/[0-9]/);
Expand Down
5 changes: 3 additions & 2 deletions src/serverExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,12 +968,13 @@ export class ServerExplorer implements TreeDataProvider<RSPState | ServerStateNo
return undefined;
}

public getServerStateById(rspId: string, serverId: string): ServerStateNode {
public getServerStateById(rspId: string, serverId: string): ServerStateNode | undefined {
return this.RSPServersStatus.get(rspId).state.serverStates.find(x => x.server.id === serverId);
}

public getServerStatesByRSP(rspId: string): ServerStateNode[] {
return this.RSPServersStatus.get(rspId).state.serverStates;
const props: RSPProperties = this.RSPServersStatus.get(rspId);
return props ? props.state.serverStates : [];
}

private isRSPElement(element: RSPState | ServerStateNode | DeployableStateNode): boolean {
Expand Down

0 comments on commit 5c8a74c

Please sign in to comment.