Skip to content

Commit

Permalink
fix delete file because trash always return undefined and doesn't rai…
Browse files Browse the repository at this point in the history
…se error if no file
  • Loading branch information
kmcb777 committed Apr 1, 2020
1 parent 5930247 commit e43ff4f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/pages/Project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { openModal } from 'reducers/modals'
import { addAlert } from 'reducers/alerts'
import { setPreview } from 'actions/preview'

import { fileDialog, saveDialog, fsWriteFile } from 'helpers/fs'
import { fileDialog, saveDialog, fsWriteFile, fileExists } from 'helpers/fs'

import Button from 'components/Button'
import ButtonDropdown from 'components/Button/ButtonDropdown'
Expand Down Expand Up @@ -99,9 +99,13 @@ export default connect(

handleRemoveFile = async fileName => {
try {
if ((await trash(fileName)) === undefined) {
throw new Error('No file was deleted')
const trashed = await trash(fileName)
const stillExists = await fileExists(fileName)

if (stillExists) {
throw new Error('File still exists')
}

this.props.addAlert('File successfully removed', 'success')
} catch (e) {
this.props.addAlert('Could not delete file', 'error')
Expand Down

0 comments on commit e43ff4f

Please sign in to comment.