From 030ddc721d0c8259ba4479fa77b4d94c1d2a4cf6 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Wed, 23 Feb 2022 21:47:27 +0100 Subject: [PATCH] sftp: show navigation errors --- tabby-ssh/src/components/sftpPanel.component.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tabby-ssh/src/components/sftpPanel.component.ts b/tabby-ssh/src/components/sftpPanel.component.ts index 7d0ec225..599e841f 100644 --- a/tabby-ssh/src/components/sftpPanel.component.ts +++ b/tabby-ssh/src/components/sftpPanel.component.ts @@ -1,7 +1,7 @@ import * as C from 'constants' import { posix as path } from 'path' import { Component, Input, Output, EventEmitter, Inject, Optional } from '@angular/core' -import { FileUpload, MenuItemOptions, PlatformService } from 'tabby-core' +import { FileUpload, MenuItemOptions, NotificationsService, PlatformService } from 'tabby-core' import { SFTPSession, SFTPFile } from '../session/sftp' import { SSHSession } from '../session/ssh' import { SFTPContextMenuItemProvider } from '../api' @@ -27,6 +27,7 @@ export class SFTPPanelComponent { constructor ( private platform: PlatformService, + private notifications: NotificationsService, @Optional() @Inject(SFTPContextMenuItemProvider) protected contextMenuProviders: SFTPContextMenuItemProvider[], ) { this.contextMenuProviders.sort((a, b) => a.weight - b.weight) @@ -38,11 +39,13 @@ export class SFTPPanelComponent { await this.navigate(this.path) } catch (error) { console.warn('Could not navigate to', this.path, ':', error) + this.notifications.error(error.message) await this.navigate('/') } } - async navigate (newPath: string): Promise { + async navigate (newPath: string, fallbackOnError = true): Promise { + const previousPath = this.path this.path = newPath this.pathChange.next(this.path) @@ -57,7 +60,15 @@ export class SFTPPanelComponent { } this.fileList = null - this.fileList = await this.sftp.readdir(this.path) + try { + this.fileList = await this.sftp.readdir(this.path) + } catch (error) { + this.notifications.error(error.message) + if (previousPath && fallbackOnError) { + this.navigate(previousPath, false) + } + return + } const dirKey = a => a.isDirectory ? 1 : 0 this.fileList.sort((a, b) =>