From 8b7939c475d4e2c46a6ae390577ed780819fd53f Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Mon, 8 Sep 2025 15:40:53 +0200 Subject: [PATCH 1/2] additional check for public drive and error handling --- src/plugins/driveBrowserPlugin.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index 0613c03..1d69ec6 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -19,7 +19,8 @@ import { IToolbarWidgetRegistry, setToolbar, showDialog, - Dialog + Dialog, + Notification } from '@jupyterlab/apputils'; import { ISettingRegistry } from '@jupyterlab/settingregistry'; import { @@ -39,8 +40,9 @@ import { Widget } from '@lumino/widgets'; import { driveBrowserIcon, removeIcon } from '../icons'; import { Drive } from '../contents'; -import { getContents, setListingLimit } from '../requests'; +import { getContents, mountDrive, setListingLimit } from '../requests'; import { CommandIDs } from '../token'; +import { DrivesResponseError } from '../handler'; /** * Status bar widget for displaying drive information @@ -535,9 +537,23 @@ namespace Private { ariaLabel: 'Add Drive' }) ] - }).then(result => { + }).then(async result => { if (result.value) { - drive.addPublicDrive(result.value); + const response = await mountDrive(result.value, { + provider: 's3' + }); + if (response && response.error) { + // Show error in case of failure. + Notification.emit( + (response.error as DrivesResponseError).message, + 'error', + { + autoClose: 5000 + } + ); + } else { + drive.addPublicDrive(result.value); + } } }); }, From 3092f5e1733d05143ba78da8dcb5de2303d79ef2 Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Mon, 8 Sep 2025 17:01:53 +0200 Subject: [PATCH 2/2] update mount function and error handling for external drives --- jupyter_drives/manager.py | 6 ++++++ src/plugins/driveBrowserPlugin.ts | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/jupyter_drives/manager.py b/jupyter_drives/manager.py index 0063f86..6923523 100644 --- a/jupyter_drives/manager.py +++ b/jupyter_drives/manager.py @@ -319,6 +319,12 @@ async def mount_drive(self, drive_name, provider, location=''): else: region = await self._get_drive_location(drive_name) self._initialize_content_manager(drive_name, provider, region) + + # check if user is able to access drive + check = await self._file_system._exists(drive_name + '/') + if check is False: + raise Exception('Failed to mount drive. Access denied.') + except Exception as e: raise tornado.web.HTTPError( status_code= httpx.codes.BAD_REQUEST, diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index 1d69ec6..2d3fe78 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -583,9 +583,24 @@ namespace Private { ariaLabel: 'Add Drive' }) ] - }).then(result => { + }).then(async result => { if (result.value) { - drive.addExternalDrive(result.value[0], result.value[1]); + const response = await mountDrive(result.value[0], { + provider: 's3', + location: result.value[1] + }); + if (response && response.error) { + // Show error in case of failure. + Notification.emit( + (response.error as DrivesResponseError).message, + 'error', + { + autoClose: 5000 + } + ); + } else { + drive.addExternalDrive(result.value[0], result.value[1]); + } } }); },