Skip to content

Commit 062989c

Browse files
committed
Files: Show error when listing dir contents fails in RemoteExplorer
Also, add test that checks that.
1 parent d05e96a commit 062989c

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

spyder/plugins/explorer/widgets/remote_explorer.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,19 @@ async def _do_remote_upload_file(self, local_path):
681681

682682
@AsyncDispatcher.QtSlot
683683
def _on_remote_ls(self, future):
684-
# TODO: We should manage errors raised by _do_remote_ls
685-
data = future.result()
686-
self.set_files(data)
684+
error = self._handle_future_response_error(
685+
future,
686+
_("List contents error"),
687+
_("An error occured while trying to view a directory"),
688+
)
689+
690+
if not error:
691+
data = future.result()
692+
self.set_files(data)
693+
else:
694+
# Set parent directory as root because the selected one can't be
695+
# accessed
696+
self.chdir(os.path.dirname(self.root_prefix[self.server_id]))
687697

688698
if not self._operation_in_progress:
689699
self.sig_stop_spinner_requested.emit()

spyder/plugins/explorer/widgets/tests/test_remote_explorer.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ def test_copy_paste(
241241
treewidget.copy_action.triggered.emit()
242242

243243
# Move to paste directory
244-
treewidget.go_to_previous_directory()
244+
with qtbot.waitSignal(treewidget.sig_stop_spinner_requested):
245+
treewidget.go_to_previous_directory()
246+
245247
qtbot.waitUntil(lambda: treewidget.model.rowCount() > 2)
246248

247249
treewidget.chdir(copy_paste_dirs[1], server_id=remote_client_id)
@@ -519,6 +521,18 @@ def test_permission_errors(
519521
assert len(QMessageBox.critical.mock_calls) == 9
520522
assert treewidget.model.rowCount() == 1
521523

524+
# Try to move to directory that can't be read
525+
with qtbot.waitSignal(treewidget.sig_stop_spinner_requested):
526+
treewidget.go_to_previous_directory()
527+
528+
with qtbot.waitSignal(treewidget.sig_stop_spinner_requested):
529+
treewidget.chdir(
530+
f"/home/ubuntu/{dirname}/cant-read-dir", server_id=remote_client_id
531+
)
532+
533+
assert len(QMessageBox.critical.mock_calls) == 10
534+
assert treewidget.model.rowCount() == 3
535+
522536

523537
if __name__ == "__main__":
524538
pytest.main()

0 commit comments

Comments
 (0)