Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Handle error when required WIT api isn't present #236

Merged
merged 2 commits into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/clients/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export abstract class BaseClient {
this._statusBarItem = statusBarItem;
}

protected handleError(err: Error, offlineText: string, polling: boolean, infoMessage?: string) : void {
protected handleError(err: Error, offlineText: string, polling: boolean, infoMessage?: string): void {
const offline: boolean = Utils.IsOffline(err);
const msg: string = Utils.GetMessageForStatusCode(err, err.message);
const logPrefix: string = (infoMessage === undefined) ? "" : infoMessage + " ";
Expand Down
51 changes: 37 additions & 14 deletions src/clients/witclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Logger } from "../helpers/logger";
import { SimpleWorkItem, WorkItemTrackingService } from "../services/workitemtracking";
import { Telemetry } from "../services/telemetry";
import { TeamServerContext} from "../contexts/servercontext";
import { BaseQuickPickItem, WorkItemQueryQuickPickItem } from "../helpers/vscodeutils";
import { BaseQuickPickItem, VsCodeUtils, WorkItemQueryQuickPickItem } from "../helpers/vscodeutils";
import { TelemetryEvents, WitQueries, WitTypes } from "../helpers/constants";
import { Strings } from "../helpers/strings";
import { Utils } from "../helpers/utils";
Expand Down Expand Up @@ -49,7 +49,7 @@ export class WitClient extends BaseClient {
Utils.OpenUrl(newItemUrl);
}
} catch (err) {
this.handleError(err, WitClient.GetOfflinePinnedQueryStatusText(), false, "Error creating new work item");
this.handleWitError(err, WitClient.GetOfflinePinnedQueryStatusText(), false, "Error creating new work item");
}
}

Expand Down Expand Up @@ -80,7 +80,7 @@ export class WitClient extends BaseClient {
}
}
} catch (err) {
this.handleError(err, WitClient.GetOfflinePinnedQueryStatusText(), false, "Error showing work item queries");
this.handleWitError(err, WitClient.GetOfflinePinnedQueryStatusText(), false, "Error showing work item queries");
}
}

Expand All @@ -91,7 +91,7 @@ export class WitClient extends BaseClient {
const queryText: string = await this.getPinnedQueryText();
await this.showWorkItems(queryText);
} catch (err) {
this.handleError(err, WitClient.GetOfflinePinnedQueryStatusText(), false, "Error showing pinned query work items");
this.handleWitError(err, WitClient.GetOfflinePinnedQueryStatusText(), false, "Error showing pinned query work items");
}
}

Expand All @@ -101,18 +101,23 @@ export class WitClient extends BaseClient {
try {
await this.showWorkItems(WitQueries.MyWorkItems);
} catch (err) {
this.handleError(err, WitClient.GetOfflinePinnedQueryStatusText(), false, "Error showing my work items");
this.handleWitError(err, WitClient.GetOfflinePinnedQueryStatusText(), false, "Error showing my work items");
}
}

public async ChooseWorkItems(): Promise<string[]> {
Logger.LogInfo("Getting work items to choose from...");
const query: string = await this.getPinnedQueryText(); //gets either MyWorkItems, queryText or wiql of queryPath of PinnedQuery
// TODO: There isn't a way to do a multi select pick list right now, but when there is we should change this to use it.
const workItem: BaseQuickPickItem = await window.showQuickPick(await this.getMyWorkItems(this._serverContext.RepoInfo.TeamProject, query), { matchOnDescription: true, placeHolder: Strings.ChooseWorkItem });
if (workItem) {
return ["#" + workItem.id + " - " + workItem.description];
} else {
try {
const query: string = await this.getPinnedQueryText(); //gets either MyWorkItems, queryText or wiql of queryPath of PinnedQuery
// TODO: There isn't a way to do a multi select pick list right now, but when there is we should change this to use it.
const workItem: BaseQuickPickItem = await window.showQuickPick(await this.getMyWorkItems(this._serverContext.RepoInfo.TeamProject, query), { matchOnDescription: true, placeHolder: Strings.ChooseWorkItem });
if (workItem) {
return ["#" + workItem.id + " - " + workItem.description];
} else {
return [];
}
} catch (err) {
this.handleWitError(err, WitClient.GetOfflinePinnedQueryStatusText(), false, "Error showing my work items in order to choose (associate)");
return [];
}
}
Expand All @@ -134,15 +139,15 @@ export class WitClient extends BaseClient {
}
}

public async GetPinnedQueryResultCount() : Promise<number> {
public async GetPinnedQueryResultCount(): Promise<number> {
try {
Logger.LogInfo("Running pinned work item query to get count (" + this._serverContext.RepoInfo.TeamProject + ")...");
const queryText: string = await this.getPinnedQueryText();

const svc: WorkItemTrackingService = new WorkItemTrackingService(this._serverContext);
return svc.GetQueryResultCount(this._serverContext.RepoInfo.TeamProject, queryText);
} catch (err) {
this.handleError(err, WitClient.GetOfflinePinnedQueryStatusText(), false, "Error getting pinned query result count");
this.handleWitError(err, WitClient.GetOfflinePinnedQueryStatusText(), false, "Error getting pinned query result count");
}
}

Expand Down Expand Up @@ -238,6 +243,24 @@ export class WitClient extends BaseClient {
return workItemTypes;
}

private handleWitError(err: Error, offlineText: string, polling: boolean, infoMessage?: string): void {
if (err.message.includes("Failed to find api location for area: wit id:")) {
Telemetry.SendEvent(TelemetryEvents.UnsupportedWitServerVersion);
const msg: string = Strings.UnsupportedWitServerVersion;
if (this._statusBarItem !== undefined) {
this._statusBarItem.text = `$(icon octicon-bug) $(icon octicon-x)`;
this._statusBarItem.tooltip = msg;
this._statusBarItem.command = undefined; //Clear the existing command
}
if (!polling) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should log the error no matter what

Logger.LogError(msg);
VsCodeUtils.ShowErrorMessage(msg);
}
} else {
this.handleError(err, offlineText, polling, infoMessage);
}
}

private logTelemetryForWorkItem(wit: string): void {
switch (wit) {
case WitTypes.Bug:
Expand All @@ -256,7 +279,7 @@ export class WitClient extends BaseClient {
this._statusBarItem.tooltip = Strings.ViewYourPinnedQuery;
this._statusBarItem.text = WitClient.GetPinnedQueryStatusText(numberOfItems.toString());
}).catch((err) => {
this.handleError(err, WitClient.GetOfflinePinnedQueryStatusText(), true, "Failed to get pinned query count during polling");
this.handleWitError(err, WitClient.GetOfflinePinnedQueryStatusText(), true, "Failed to get pinned query count during polling");
});
}

Expand Down
1 change: 1 addition & 0 deletions src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class TelemetryEvents {
static TokenLearnMoreClick: string = TelemetryEvents.TelemetryPrefix + "tokenlearnmoreclick";
static TokenShowMeClick: string = TelemetryEvents.TelemetryPrefix + "tokenshowmeclick";
static UnsupportedServerVersion: string = TelemetryEvents.TelemetryPrefix + "unsupportedversion";
static UnsupportedWitServerVersion: string = TelemetryEvents.TelemetryPrefix + "unsupportedwitversion";
static ViewPullRequest: string = TelemetryEvents.TelemetryPrefix + "viewpullrequest";
static ViewPullRequests: string = TelemetryEvents.TelemetryPrefix + "viewpullrequests";
static ViewMyWorkItems: string = TelemetryEvents.TelemetryPrefix + "viewmyworkitems";
Expand Down
1 change: 1 addition & 0 deletions src/helpers/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class Strings {
static ProvidePassword: string = "Provide the password for username";
static ProvideUsername: string = "Provide the username for server";

static UnsupportedWitServerVersion: string = "Work Item Tracking (WIT) functionality is disabled. WIT functionality requires TFS version 2015 Update 2 or later.";
static UnsupportedServerVersion: string = "The Team Services extension only supports TFS version 2015 Update 2 or later. Please verify your TFS server version.";
static UnableToRemoveCredentials: string = "Unable to remove credentials for this host. You may need to remove them manually. Host: ";
static UnableToStoreCredentials: string = "Unable to store credentials for this host. Host: ";
Expand Down