Skip to content

Commit

Permalink
utils: Handle showInputBox errors that could be thrown during valid…
Browse files Browse the repository at this point in the history
…ation (#1879)
  • Loading branch information
MicroFish91 authored Jan 30, 2025
1 parent 8eec250 commit 012787d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions utils/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion utils/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@microsoft/vscode-azext-utils",
"author": "Microsoft Corporation",
"version": "2.5.12",
"version": "2.5.13",
"description": "Common UI tools for developing Azure extensions for VS Code",
"tags": [
"azure",
Expand Down
22 changes: 14 additions & 8 deletions utils/src/userInput/showInputBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Disposable, InputBox, InputBoxOptions, QuickInputButton, QuickInputButt
import * as types from '../../index';
import { AzExtQuickInputButtons } from '../constants';
import { GoBackError, UserCancelledError } from '../errors';
import { parseError } from '../parseError';
import { validOnTimeoutOrException } from '../utils/inputValidation';
import { nonNullProp } from '../utils/nonNull';
import { openUrl } from '../utils/openUrl';
Expand Down Expand Up @@ -38,14 +39,19 @@ export async function showInputBox(context: IInternalActionContext, options: typ
inputBox.enabled = false;
inputBox.busy = true;

const validateInputResult: InputBoxValidationResult = await latestValidation;
const asyncValidationResult: string | undefined | null = options.asyncValidationTask ? await options.asyncValidationTask(inputBox.value) : undefined;
if (!validateInputResult && !asyncValidationResult) {
resolve(inputBox.value);
} else if (validateInputResult) {
inputBox.validationMessage = validateInputResult;
} else if (asyncValidationResult) {
inputBox.validationMessage = asyncValidationResult;
try {
const validateInputResult: InputBoxValidationResult = await latestValidation;
const asyncValidationResult: string | undefined | null = options.asyncValidationTask ? await options.asyncValidationTask(inputBox.value) : undefined;
if (!validateInputResult && !asyncValidationResult) {
resolve(inputBox.value);
} else if (validateInputResult) {
inputBox.validationMessage = validateInputResult;
} else if (asyncValidationResult) {
inputBox.validationMessage = asyncValidationResult;
}
} catch (e) {
const pe: types.IParsedError = parseError(e);
reject(pe.message);
}

inputBox.enabled = true;
Expand Down

0 comments on commit 012787d

Please sign in to comment.