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

[stable30] fix(files): failsafe when executing actions methods #49792

Open
wants to merge 2 commits into
base: stable30
Choose a base branch
from
Open
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
39 changes: 29 additions & 10 deletions apps/files/src/components/FileEntry/FileEntryActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,14 @@ export default defineComponent({
if (this.filesListWidth < 768 || this.gridMode) {
return []
}
return this.enabledFileActions.filter(action => action?.inline?.(this.source, this.currentView))
return this.enabledFileActions.filter(action => {
try {
return action?.inline?.(this.source, this.currentView)
} catch (error) {
logger.error('Error while checking if action is inline', { action, error })
return false
}
})
},

// Enabled action that are displayed inline with a custom render function
Expand Down Expand Up @@ -236,13 +243,19 @@ export default defineComponent({

methods: {
actionDisplayName(action: FileAction) {
if ((this.gridMode || (this.filesListWidth < 768 && action.inline)) && typeof action.title === 'function') {
// if an inline action is rendered in the menu for
// lack of space we use the title first if defined
const title = action.title([this.source], this.currentView)
if (title) return title
try {
if ((this.gridMode || (this.filesListWidth < 768 && action.inline)) && typeof action.title === 'function') {
// if an inline action is rendered in the menu for
// lack of space we use the title first if defined
const title = action.title([this.source], this.currentView)
if (title) return title
}
return action.displayName([this.source], this.currentView)
} catch (error) {
logger.error('Error while getting action display name', { action, error })
// Not ideal, but better than nothing
return action.id
}
return action.displayName([this.source], this.currentView)
},

async onActionClick(action, isSubmenu = false) {
Expand All @@ -257,7 +270,13 @@ export default defineComponent({
return
}

const displayName = action.displayName([this.source], this.currentView)
let displayName = action.id
try {
displayName = action.displayName([this.source], this.currentView)
} catch (error) {
logger.error('Error while getting action display name', { action, error })
}

try {
// Set the loading marker
this.$emit('update:loading', action.id)
Expand All @@ -275,8 +294,8 @@ export default defineComponent({
return
}
showError(t('files', '"{displayName}" action failed', { displayName }))
} catch (e) {
logger.error('Error while executing action', { action, e })
} catch (error) {
logger.error('Error while executing action', { action, error })
showError(t('files', '"{displayName}" action failed', { displayName }))
} finally {
// Reset the loading marker
Expand Down
19 changes: 16 additions & 3 deletions apps/files/src/components/FileEntryMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
import type { PropType } from 'vue'
import type { FileSource } from '../types.ts'

import { showError } from '@nextcloud/dialogs'
import { extname } from 'path'

Check failure on line 9 in apps/files/src/components/FileEntryMixin.ts

View workflow job for this annotation

GitHub Actions / NPM lint

'path' imported multiple times
import { FileType, Permission, Folder, File as NcFile, NodeStatus, Node, getFileActions } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
import { vOnClickOutside } from '@vueuse/components'
import { extname } from 'path'

Check failure on line 13 in apps/files/src/components/FileEntryMixin.ts

View workflow job for this annotation

GitHub Actions / NPM lint

'path' imported multiple times
import Vue, { defineComponent } from 'vue'

import { action as sidebarAction } from '../actions/sidebarAction.ts'
import { dataTransferToFileTree, onDropExternalFiles, onDropInternalFiles } from '../services/DropService.ts'

Check failure on line 17 in apps/files/src/components/FileEntryMixin.ts

View workflow job for this annotation

GitHub Actions / NPM lint

'/home/runner/actions-runner/_work/server/server/apps/files/src/services/DropService.ts' imported multiple times
import { getDragAndDropPreview } from '../utils/dragUtils.ts'
import { hashCode } from '../utils/hashUtils.ts'
import { dataTransferToFileTree, onDropExternalFiles, onDropInternalFiles } from '../services/DropService.ts'

Check failure on line 20 in apps/files/src/components/FileEntryMixin.ts

View workflow job for this annotation

GitHub Actions / NPM lint

'/home/runner/actions-runner/_work/server/server/apps/files/src/services/DropService.ts' imported multiple times
import logger from '../logger.ts'

Vue.directive('onClickOutside', vOnClickOutside)
Expand Down Expand Up @@ -198,7 +198,20 @@
}

return actions
.filter(action => !action.enabled || action.enabled([this.source], this.currentView))
.filter(action => {
if (!action.enabled) {
return true
}

// In case something goes wrong, since we don't want to break
// the entire list, we filter out actions that throw an error.
try {
return action.enabled([this.source], this.currentView)
} catch (error) {
logger.error('Error while checking action', { action, error })
return false
}
})
.sort((a, b) => (a.order || 0) - (b.order || 0))
},

Expand Down
Loading