Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: Handle showInputBox errors that could be thrown during validation #1879

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
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