Handle broken plugin install
This commit is contained in:
parent
4c0a6954fb
commit
9c2e051c56
|
@ -304,22 +304,28 @@ export class PluginManager implements ServerHook {
|
||||||
uninstalled: false,
|
uninstalled: false,
|
||||||
peertubeEngine: packageJSON.engine.peertube
|
peertubeEngine: packageJSON.engine.peertube
|
||||||
}, { returning: true })
|
}, { returning: true })
|
||||||
} catch (err) {
|
|
||||||
logger.error('Cannot install plugin %s, removing it...', toInstall, { err })
|
logger.info('Successful installation of plugin %s.', toInstall)
|
||||||
|
|
||||||
|
await this.registerPluginOrTheme(plugin)
|
||||||
|
} catch (rootErr) {
|
||||||
|
logger.error('Cannot install plugin %s, removing it...', toInstall, { err: rootErr })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await removeNpmPlugin(npmName)
|
await this.uninstall(npmName)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('Cannot remove plugin %s after failed installation.', toInstall, { err })
|
logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err })
|
||||||
|
|
||||||
|
try {
|
||||||
|
await removeNpmPlugin(npmName)
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('Cannot remove plugin %s after failed installation.', toInstall, { err })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw err
|
throw rootErr
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info('Successful installation of plugin %s.', toInstall)
|
|
||||||
|
|
||||||
await this.registerPluginOrTheme(plugin)
|
|
||||||
|
|
||||||
return plugin
|
return plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,8 +431,7 @@ export class PluginManager implements ServerHook {
|
||||||
|
|
||||||
await ensureDir(registerOptions.peertubeHelpers.plugin.getDataDirectoryPath())
|
await ensureDir(registerOptions.peertubeHelpers.plugin.getDataDirectoryPath())
|
||||||
|
|
||||||
library.register(registerOptions)
|
await library.register(registerOptions)
|
||||||
.catch(err => logger.error('Cannot register plugin %s.', npmName, { err }))
|
|
||||||
|
|
||||||
logger.info('Add plugin %s CSS to global file.', npmName)
|
logger.info('Add plugin %s CSS to global file.', npmName)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
|
import { HttpStatusCode } from '@shared/core-utils'
|
||||||
import {
|
import {
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
closeAllSequelize,
|
closeAllSequelize,
|
||||||
|
@ -10,6 +11,7 @@ import {
|
||||||
getMyUserInformation,
|
getMyUserInformation,
|
||||||
getPlugin,
|
getPlugin,
|
||||||
getPluginPackageJSON,
|
getPluginPackageJSON,
|
||||||
|
getPluginTestPath,
|
||||||
getPublicSettings,
|
getPublicSettings,
|
||||||
installPlugin,
|
installPlugin,
|
||||||
killallServers,
|
killallServers,
|
||||||
|
@ -400,6 +402,36 @@ describe('Test plugins', function () {
|
||||||
expect((res.body as User).theme).to.equal('instance-default')
|
expect((res.body as User).theme).to.equal('instance-default')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should not install a broken plugin', async function () {
|
||||||
|
this.timeout(60000)
|
||||||
|
|
||||||
|
async function check () {
|
||||||
|
const res = await listPlugins({
|
||||||
|
url: server.url,
|
||||||
|
accessToken: server.accessToken,
|
||||||
|
pluginType: PluginType.PLUGIN
|
||||||
|
})
|
||||||
|
|
||||||
|
const plugins: PeerTubePlugin[] = res.body.data
|
||||||
|
|
||||||
|
expect(plugins.find(p => p.name === 'test-broken')).to.not.exist
|
||||||
|
}
|
||||||
|
|
||||||
|
await installPlugin({
|
||||||
|
url: server.url,
|
||||||
|
accessToken: server.accessToken,
|
||||||
|
path: getPluginTestPath('-broken'),
|
||||||
|
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
||||||
|
})
|
||||||
|
|
||||||
|
await check()
|
||||||
|
|
||||||
|
killallServers([ server ])
|
||||||
|
await reRunServer(server)
|
||||||
|
|
||||||
|
await check()
|
||||||
|
})
|
||||||
|
|
||||||
after(async function () {
|
after(async function () {
|
||||||
await closeAllSequelize([ server ])
|
await closeAllSequelize([ server ])
|
||||||
await cleanupTests([ server ])
|
await cleanupTests([ server ])
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
async function register (options) {
|
||||||
|
options.unknownFunction()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function unregister () {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
register,
|
||||||
|
unregister
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"name": "peertube-plugin-test-broken",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "Plugin test broken",
|
||||||
|
"engine": {
|
||||||
|
"peertube": ">=1.3.0"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"peertube",
|
||||||
|
"plugin"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/Chocobozzz/PeerTube",
|
||||||
|
"author": "Chocobozzz",
|
||||||
|
"bugs": "https://github.com/Chocobozzz/PeerTube/issues",
|
||||||
|
"library": "./main.js",
|
||||||
|
"staticDirs": {},
|
||||||
|
"css": [],
|
||||||
|
"clientScripts": [],
|
||||||
|
"translations": {}
|
||||||
|
}
|
Loading…
Reference in New Issue