Skip to content

Commit

Permalink
wip(fix): Make 401 handling rigid for FS lookup
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Feb 24, 2025
1 parent 53c1630 commit 895e8a9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
33 changes: 23 additions & 10 deletions packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,31 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem
this.createDirectory(profileUri);
}

if (uriInfo.isRoot) {
// profile entry; check if "pattern" filter is in query.
try {
// Wait for any ongoing authentication to complete
await AuthHandler.waitForUnlock(uriInfo.profile);

if (uriInfo.isRoot) {
// profile entry; check if "pattern" filter is in query.
const urlQuery = new URLSearchParams(uri.query);
if (!urlQuery.has("pattern")) {
return this._lookupAsDirectory(profileUri, false);

Check warning on line 298 in packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts#L298

Added line #L298 was not covered by tests
}

const urlQuery = new URLSearchParams(uri.query);
if (!urlQuery.has("pattern")) {
return this._lookupAsDirectory(profileUri, false);
return this.fetchEntriesForProfile(uri, uriInfo, urlQuery.get("pattern"));
} else {
// data set or one of its members
return this.fetchDataset(uri, uriInfo);
}

return this.fetchEntriesForProfile(uri, uriInfo, urlQuery.get("pattern"));
} else {
// data set or one of its members
return this.fetchDataset(uri, uriInfo);
} catch (err) {
await AuthUtils.handleProfileAuthOnError(err, uriInfo.profile);
// If the profile is locked (authentication failed), throw an error to prevent further attempts
if (AuthHandler.isProfileLocked(uriInfo.profile)) {
throw vscode.FileSystemError.NoPermissions(

Check warning on line 310 in packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts#L310

Added line #L310 was not covered by tests
vscode.l10n.t("Authentication failed. Please update credentials through the 'Update Credentials' command.")
);
}
throw err;

Check warning on line 314 in packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts#L314

Added line #L314 was not covered by tests
}
}

Expand Down
28 changes: 20 additions & 8 deletions packages/zowe-explorer/src/trees/uss/UssFSProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,33 @@ export class UssFSProvider extends BaseProvider implements vscode.FileSystemProv
public async remoteLookupForResource(uri: vscode.Uri): Promise<UssDirectory | UssFile> {
const uriInfo = FsAbstractUtils.getInfoForUri(uri, Profiles.getInstance());
const profileUri = vscode.Uri.from({ scheme: ZoweScheme.USS, path: uriInfo.profileName });

// Ensure that an entry exists for the given profile
if (!this.exists(profileUri)) {
this.createDirectory(profileUri);
}

if (uriInfo.isRoot) {
// profile entry; check if "pattern" is in query.
const urlQuery = new URLSearchParams(uri.query);
if (!urlQuery.has("searchPath")) {
return this._lookupAsDirectory(profileUri, false) as UssDirectory;
try {
await AuthHandler.waitForUnlock(uriInfo.profile);

Check warning on line 229 in packages/zowe-explorer/src/trees/uss/UssFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/uss/UssFSProvider.ts#L228-L229

Added lines #L228 - L229 were not covered by tests
if (uriInfo.isRoot) {
// profile entry; check if "searchPath" is in query.
const urlQuery = new URLSearchParams(uri.query);

Check warning on line 232 in packages/zowe-explorer/src/trees/uss/UssFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/uss/UssFSProvider.ts#L232

Added line #L232 was not covered by tests
if (!urlQuery.has("searchPath")) {
return this._lookupAsDirectory(profileUri, false) as UssDirectory;

Check warning on line 234 in packages/zowe-explorer/src/trees/uss/UssFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/uss/UssFSProvider.ts#L234

Added line #L234 was not covered by tests
}
}
return this.fetchEntries(uri, uriInfo);

Check warning on line 237 in packages/zowe-explorer/src/trees/uss/UssFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/uss/UssFSProvider.ts#L237

Added line #L237 was not covered by tests
} catch (err) {
// Handle authentication errors through AuthHandler
await AuthUtils.handleProfileAuthOnError(err, uriInfo.profile);

Check warning on line 240 in packages/zowe-explorer/src/trees/uss/UssFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/uss/UssFSProvider.ts#L240

Added line #L240 was not covered by tests

// If the profile is locked (authentication failed), throw an error to prevent further attempts
if (AuthHandler.isProfileLocked(uriInfo.profile)) {
throw vscode.FileSystemError.NoPermissions(

Check warning on line 244 in packages/zowe-explorer/src/trees/uss/UssFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/uss/UssFSProvider.ts#L244

Added line #L244 was not covered by tests
vscode.l10n.t("Authentication failed. Please update credentials through the 'Update Credentials' command.")
);
}
throw err;

Check warning on line 248 in packages/zowe-explorer/src/trees/uss/UssFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/uss/UssFSProvider.ts#L248

Added line #L248 was not covered by tests
}

return this.fetchEntries(uri, uriInfo);
}

/**
Expand Down

0 comments on commit 895e8a9

Please sign in to comment.