Fix null ref error when no database or server node are in object tree (#1790)

- Also fixed minor issue where `var` was used instead of `let` in a related file, since this is discouraged in our codebase.
This commit is contained in:
Kevin Cunnane
2018-06-29 16:49:46 -07:00
committed by GitHub
parent 1819036d7d
commit 335f667507
2 changed files with 7 additions and 7 deletions

View File

@@ -96,11 +96,11 @@ export class TreeNode {
return undefined; return undefined;
} }
var currentNode: TreeNode = this; var currentNode: TreeNode = this;
while (currentNode.nodeTypeId !== NodeType.Database && currentNode.nodeTypeId !== NodeType.Server) { while (currentNode.nodeTypeId !== NodeType.Database && currentNode.nodeTypeId !== NodeType.Server && currentNode.parent) {
currentNode = currentNode.parent; currentNode = currentNode.parent;
} }
if (currentNode.nodeTypeId === NodeType.Database) { if (currentNode && currentNode.nodeTypeId === NodeType.Database) {
return currentNode.metadata ? currentNode.metadata.name : null; return currentNode.metadata ? currentNode.metadata.name : null;
} }
return undefined; return undefined;

View File

@@ -181,7 +181,7 @@ export class TreeUpdateUtils {
connectedConnection.options['groupId'] = connection.groupId; connectedConnection.options['groupId'] = connection.groupId;
connectedConnection.options['databaseDisplayName'] = connection.databaseName; connectedConnection.options['databaseDisplayName'] = connection.databaseName;
var rootNode: TreeNode = objectExplorerService.getObjectExplorerNode(connectedConnection); let rootNode: TreeNode = objectExplorerService.getObjectExplorerNode(connectedConnection);
if (!rootNode) { if (!rootNode) {
objectExplorerService.updateObjectExplorerNodes(connectedConnection).then(() => { objectExplorerService.updateObjectExplorerNodes(connectedConnection).then(() => {
rootNode = objectExplorerService.getObjectExplorerNode(connectedConnection); rootNode = objectExplorerService.getObjectExplorerNode(connectedConnection);
@@ -207,7 +207,7 @@ export class TreeUpdateUtils {
if (connection.isDisconnecting) { if (connection.isDisconnecting) {
resolve([]); resolve([]);
} else { } else {
var rootNode = objectExplorerService.getObjectExplorerNode(connection); let rootNode = objectExplorerService.getObjectExplorerNode(connection);
if (rootNode) { if (rootNode) {
objectExplorerService.resolveTreeNodeChildren(rootNode.getSession(), rootNode).then(() => { objectExplorerService.resolveTreeNodeChildren(rootNode.getSession(), rootNode).then(() => {
resolve(rootNode.children); resolve(rootNode.children);
@@ -226,7 +226,7 @@ export class TreeUpdateUtils {
if (objectExplorerNode && objectExplorerNode.parent) { if (objectExplorerNode && objectExplorerNode.parent) {
// if object explorer node's parent is root, return connection profile // if object explorer node's parent is root, return connection profile
if (!objectExplorerNode.parent.parent) { if (!objectExplorerNode.parent.parent) {
var connectionId = objectExplorerNode.getConnectionProfile().id; let connectionId = objectExplorerNode.getConnectionProfile().id;
// get connection profile from connection profile groups // get connection profile from connection profile groups
let root = TreeUpdateUtils.getTreeInput(connectionManagementService); let root = TreeUpdateUtils.getTreeInput(connectionManagementService);
@@ -268,8 +268,8 @@ export class TreeUpdateUtils {
* Get connection profile with the current database * Get connection profile with the current database
*/ */
public static getConnectionProfile(treeNode: TreeNode): ConnectionProfile { public static getConnectionProfile(treeNode: TreeNode): ConnectionProfile {
var connectionProfile = treeNode.getConnectionProfile(); let connectionProfile = treeNode.getConnectionProfile();
var databaseName = treeNode.getDatabaseName(); let databaseName = treeNode.getDatabaseName();
if (databaseName !== undefined && connectionProfile.databaseName !== databaseName) { if (databaseName !== undefined && connectionProfile.databaseName !== databaseName) {
connectionProfile = connectionProfile.cloneWithDatabase(databaseName); connectionProfile = connectionProfile.cloneWithDatabase(databaseName);
} }