Skip to content

Commit 191eb3f

Browse files
committed
refactor: unified all error messages
1 parent 1fabb49 commit 191eb3f

File tree

9 files changed

+15
-15
lines changed

9 files changed

+15
-15
lines changed

packages/devtools-kit/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function extendServerRpc<ClientFunctions = Record<string, never>, ServerF
129129
): BirpcGroup<ClientFunctions, ServerFunctions> {
130130
const ctx = _getContext(nuxt)
131131
if (!ctx)
132-
throw new Error('Failed to get devtools context.')
132+
throw new Error('[Nuxt DevTools] Failed to get devtools context.')
133133

134134
return ctx.extendServerRpc<ClientFunctions, ServerFunctions>(namespace, functions)
135135
}

packages/devtools-wizard/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ async function run() {
2727
consola.log(`\n${colors.gray('Learn more at https://devtools.nuxt.com\n')}`)
2828

2929
if (moduleName.endsWith('-edge') || moduleName.endsWith('-nightly'))
30-
throw new Error('Nightly release of Nuxt DevTools requires to be installed locally. Learn more at https://github.com/nuxt/devtools/#nightly-release-channel')
30+
throw new Error('[Nuxt DevTools] Nightly release of Nuxt DevTools requires to be installed locally. Learn more at https://github.com/nuxt/devtools/#nightly-release-channel')
3131

3232
const nuxtVersion = await getNuxtVersion(cwd)
3333
if (!nuxtVersion) {
34-
consola.error('Unable to find any installed nuxt version in the current directory')
34+
consola.error('[Nuxt DevTools] Unable to find any installed nuxt version in the current directory')
3535
process.exit(1)
3636
}
3737
if (command === 'enable') {

packages/devtools/client/composables/dev-auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function ensureDevAuthToken() {
4747
classes: 'text-red',
4848
})
4949
await authConfirmAction()
50-
throw new Error('Invalid auth token')
50+
throw new Error('[Nuxt DevTools] Invalid auth token')
5151
}
5252

5353
return devAuthToken.value!
@@ -83,6 +83,6 @@ async function authConfirmAction() {
8383
icon: 'carbon-close',
8484
classes: 'text-orange',
8585
})
86-
throw new Error('User canceled auth')
86+
throw new Error('[Nuxt DevTools] User canceled auth')
8787
}
8888
}

packages/devtools/client/composables/rpc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ async function connectVite() {
6969

7070
if (!hot) {
7171
wsConnecting.value = true
72-
console.error('[nuxt-devtools] Unable to find Vite HMR context')
73-
throw new Error('Unable to connect to devtools')
72+
console.error('[Nuxt DevTools] Unable to find Vite HMR context')
73+
throw new Error('[Nuxt DevTools] Unable to connect to devtools')
7474
}
7575

7676
hot.on(WS_EVENT_NAME, (data) => {

packages/devtools/src/server-rpc/analyze-build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function setupAnalyzeBuildRPC({ nuxt, refresh, ensureDevAuthToken }: Nuxt
1717

1818
async function startAnalyzeBuild(name: string) {
1919
if (promise)
20-
throw new Error('Already building')
20+
throw new Error('[Nuxt DevTools] A building process is already running')
2121

2222
const result = startSubprocess({
2323
command: 'npx',

packages/devtools/src/server-rpc/assets.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ export function setupAssetsRPC({ nuxt, ensureDevAuthToken, refresh, options }: N
112112
files.map(async ({ path, content, encoding, override }) => {
113113
let finalPath = resolve(baseDir, path)
114114
if (!finalPath.startsWith(baseDir))
115-
throw new Error(`File ${path} is not allowed to upload, it's outside of the public directory`)
115+
throw new Error(`[Nuxt DevTools] File ${path} is not allowed to upload, it's outside of the public directory`)
116116

117117
const { ext } = parse(finalPath)
118118
if (extensions !== '*') {
119119
if (!extensions.includes(ext.toLowerCase().slice(1)))
120-
throw new Error(`File extension ${ext} is not allowed to upload, allowed extensions are: ${extensions.join(', ')}\nYou can configure it in Nuxt config at \`devtools.assets.uploadExtensions\`.`)
120+
throw new Error(`[Nuxt DevTools] File extension ${ext} is not allowed to upload, allowed extensions are: ${extensions.join(', ')}\nYou can configure it in Nuxt config at \`devtools.assets.uploadExtensions\`.`)
121121
}
122122

123123
if (!override) {
@@ -150,7 +150,7 @@ export function setupAssetsRPC({ nuxt, ensureDevAuthToken, refresh, options }: N
150150

151151
const exist = cache?.find(asset => asset.filePath === newPath)
152152
if (exist)
153-
throw new Error(`File ${newPath} already exists`)
153+
throw new Error(`[Nuxt DevTools] File ${newPath} already exists, failed to rename`)
154154
return await fsp.rename(oldPath, newPath)
155155
},
156156
} satisfies Partial<ServerFunctions>

packages/devtools/src/server-rpc/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function setupRPC(nuxt: Nuxt, options: ModuleOptions) {
8181
if (options.disableAuthorization)
8282
return
8383
if (token !== await getDevAuthToken())
84-
throw new Error('Invalid dev auth token.')
84+
throw new Error('[Nuxt DevTools] Invalid dev auth token.')
8585
},
8686
}
8787

packages/devtools/src/server-rpc/npm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function setupNpmRPC({ nuxt, ensureDevAuthToken }: NuxtDevtoolsServerCont
132132
const code = result.exitCode
133133
if (code !== 0) {
134134
console.error(result.stderr)
135-
throw new Error(`Failed to install module, process exited with ${code}`)
135+
throw new Error(`[Nuxt DevTools] Failed to install module, process exited with ${code}`)
136136
}
137137

138138
// If all modules have been installed, write back to the config file, and auto restart.
@@ -193,7 +193,7 @@ export function setupNpmRPC({ nuxt, ensureDevAuthToken }: NuxtDevtoolsServerCont
193193
const code = result.exitCode
194194
if (code !== 0) {
195195
console.error(result.stderr)
196-
throw new Error(`Failed to uninstall module', process exited with ${code}`)
196+
throw new Error(`[Nuxt DevTools] Failed to uninstall module, process exited with ${code}`)
197197
}
198198

199199
await fs.writeFile(filepath, generated, 'utf-8')

packages/devtools/src/utils/magicast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export async function magicastGuard(fn: (() => Promise<string>), message = '') {
88
}
99
catch (e) {
1010
logger.error(e)
11-
throw new Error(`Magicast failed to modify Nuxt config automatically. Maybe the config are composed too dynamically that we failed to statically analyze it. ${message}`)
11+
throw new Error(`[Nuxt DevTools] Magicast failed to modify Nuxt config automatically. Maybe the config are composed too dynamically that we failed to statically analyze it. ${message}`)
1212
}
1313

1414
return generated

0 commit comments

Comments
 (0)