fix: handle BinaryManager removal errors

This commit is contained in:
Jonathan Finley 2026-03-13 23:46:24 -04:00
parent 9a6591fa59
commit 3489feaf67
2 changed files with 30 additions and 2 deletions

View file

@ -369,14 +369,14 @@ class BinaryManager {
* @param {Binary} binary * @param {Binary} binary
*/ */
async removeBinary(destination, binary) { async removeBinary(destination, binary) {
try {
const binaryPath = path.join(destination, binary.fileName) const binaryPath = path.join(destination, binary.fileName)
try {
if (await fs.pathExists(binaryPath)) { if (await fs.pathExists(binaryPath)) {
Logger.debug(`[BinaryManager] Removing binary: ${binaryPath}`) Logger.debug(`[BinaryManager] Removing binary: ${binaryPath}`)
await fs.remove(binaryPath) await fs.remove(binaryPath)
} }
} catch (err) { } catch (err) {
Logger.error(`[BinaryManager] Error removing binary: ${binaryPath}`) Logger.error(`[BinaryManager] Error removing binary: ${binaryPath}`, err)
} }
} }

View file

@ -4,6 +4,7 @@ const fs = require('../../../server/libs/fsExtra')
const fileUtils = require('../../../server/utils/fileUtils') const fileUtils = require('../../../server/utils/fileUtils')
const which = require('../../../server/libs/which') const which = require('../../../server/libs/which')
const path = require('path') const path = require('path')
const Logger = require('../../../server/Logger')
const BinaryManager = require('../../../server/managers/BinaryManager') const BinaryManager = require('../../../server/managers/BinaryManager')
const { Binary, ffbinaries } = require('../../../server/managers/BinaryManager') const { Binary, ffbinaries } = require('../../../server/managers/BinaryManager')
@ -203,6 +204,33 @@ describe('BinaryManager', () => {
expect(downloadBinaryStub.calledWith(destination)).to.be.true expect(downloadBinaryStub.calledWith(destination)).to.be.true
}) })
}) })
describe('removeBinary', () => {
let pathExistsStub
let errorStub
beforeEach(() => {
binaryManager = new BinaryManager()
pathExistsStub = sinon.stub(fs, 'pathExists').rejects(new Error('remove failed'))
errorStub = sinon.stub(Logger, 'error')
})
afterEach(() => {
pathExistsStub.restore()
errorStub.restore()
})
it('logs the resolved binary path when removal fails', async () => {
const destination = '/path/to/install'
const binary = { fileName: 'ffmpeg' }
await binaryManager.removeBinary(destination, binary)
expect(errorStub.calledOnce).to.be.true
expect(errorStub.firstCall.args[0]).to.include(path.join(destination, binary.fileName))
expect(errorStub.firstCall.args[1]).to.be.an('error')
})
})
}) })
describe('Binary', () => { describe('Binary', () => {