Skip to content

Commit 23a05fc

Browse files
author
Guillaume Chau
committed
fix(plugin): catch execution error
1 parent c500512 commit 23a05fc

File tree

1 file changed

+17
-4
lines changed
  • packages/@vue/cli-ui/apollo-server/connectors

1 file changed

+17
-4
lines changed

packages/@vue/cli-ui/apollo-server/connectors/plugins.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ function resetPluginApi ({ file, lightApi }, context) {
229229
}
230230

231231
function runPluginApi (id, pluginApi, context, filename = 'ui') {
232+
const name = filename !== 'ui' ? `${id}/${filename}` : id
233+
232234
let module
233235
try {
234236
module = loadModule(`${id}/${filename}`, pluginApi.cwd, true)
@@ -239,12 +241,23 @@ function runPluginApi (id, pluginApi, context, filename = 'ui') {
239241
}
240242
if (module) {
241243
if (typeof module !== 'function') {
242-
log(`${chalk.red('ERROR')} while loading plugin API: no function exported, for`, filename !== 'ui' ? `${id}/${filename}` : id, chalk.grey(pluginApi.cwd))
244+
log(`${chalk.red('ERROR')} while loading plugin API: no function exported, for`, name, chalk.grey(pluginApi.cwd))
245+
logs.add({
246+
type: 'error',
247+
message: `An error occured while loading ${name}: no function exported`
248+
})
243249
} else {
244-
const name = filename !== 'ui' ? `${id}/${filename}` : id
245-
log('Plugin API loaded for', name, chalk.grey(pluginApi.cwd))
246250
pluginApi.pluginId = id
247-
module(pluginApi)
251+
try {
252+
module(pluginApi)
253+
log('Plugin API loaded for', name, chalk.grey(pluginApi.cwd))
254+
} catch (e) {
255+
log(`${chalk.red('ERROR')} while loading plugin API for ${name}:`, e)
256+
logs.add({
257+
type: 'error',
258+
message: `An error occured while loading ${name}: ${e.message}`
259+
})
260+
}
248261
pluginApi.pluginId = null
249262
}
250263
}

0 commit comments

Comments
 (0)