Skip to content

Commit

Permalink
feature: improve server start error message (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
levivilet authored Dec 27, 2024
1 parent a0cfe8a commit 958d5d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import type { WebViewServer } from '../WebViewServerTypes/WebViewServerTypes.ts'

const servers = Object.create(null)
const servers: Record<number, WebViewServer> = Object.create(null)

export const set = (id: number, server: WebViewServer): void => {
servers[id] = server
}

export const get = (id: number): WebViewServer => {
return servers[id]
const server = servers[id]
if (!server) {
throw new Error(`Server with id ${id} not found`)
}
return server
}

export const has = (id: number): boolean => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('preview process - handles port already in use', async () => {
const port = await getPort()
// TODO improve error message
await expect(previewProcess1.invoke('WebViewServer.start', id, port)).rejects.toThrow(
"Failed to start webview server: TypeError: Cannot read properties of undefined (reading 'server')",
'Failed to start webview server: Server with id 1 not found',
)
previewProcess1[Symbol.dispose]()
})

0 comments on commit 958d5d2

Please sign in to comment.