Skip to content

Commit

Permalink
fix: failed to bind port - nitro error message copy (janhq#2101)
Browse files Browse the repository at this point in the history
* fix: failed to bind port - nitro error message copy

* fix: copy
  • Loading branch information
louis-jan authored Feb 20, 2024
1 parent 6b88d4d commit 7fbc6cb
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 23 deletions.
5 changes: 4 additions & 1 deletion extensions/inference-nitro-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ export default class JanInferenceNitroExtension extends InferenceExtension {
})

if (nitroInitResult?.error) {
events.emit(ModelEvent.OnModelFail, model)
events.emit(ModelEvent.OnModelFail, {
...model,
error: nitroInitResult.error,
})
return
}

Expand Down
8 changes: 7 additions & 1 deletion extensions/inference-nitro-extension/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,15 @@ async function killSubprocess(): Promise<void> {
subprocess?.kill()
subprocess = undefined
})
.catch(() => {})
.catch(() => {}) // Do nothing with this attempt
.then(() => tcpPortUsed.waitUntilFree(PORT, 300, 5000))
.then(() => log(`[NITRO]::Debug: Nitro process is terminated`))
.catch((err) => {
log(
`[NITRO]::Debug: Could not kill running process on port ${PORT}. Might be another process running on the same port? ${err}`
)
throw 'PORT_NOT_AVAILABLE'
})
}

/**
Expand Down
4 changes: 2 additions & 2 deletions web/containers/Providers/EventHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export default function EventHandler({ children }: { children: ReactNode }) {

const onModelInitFailed = useCallback(
(res: any) => {
const errorMessage = `${res.error}`
console.error('Failed to load model: ' + errorMessage)
const errorMessage = res?.error ?? res
console.error('Failed to load model: ', errorMessage)
setStateModel(() => ({
state: 'start',
loading: false,
Expand Down
63 changes: 44 additions & 19 deletions web/screens/Chat/ErrorMessage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ModalTroubleShooting, {
modalTroubleShootingAtom,
} from '@/containers/ModalTroubleShoot'

import { loadModelErrorAtom } from '@/hooks/useActiveModel'
import useSendChatMessage from '@/hooks/useSendChatMessage'

import { getCurrentChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom'
Expand All @@ -15,6 +16,8 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => {
const messages = useAtomValue(getCurrentChatMessagesAtom)
const { resendChatMessage } = useSendChatMessage()
const setModalTroubleShooting = useSetAtom(modalTroubleShootingAtom)
const loadModelError = useAtomValue(loadModelErrorAtom)
const PORT_NOT_AVAILABLE = 'PORT_NOT_AVAILABLE'

const regenerateMessage = async () => {
const lastMessageIndex = messages.length - 1
Expand All @@ -23,9 +26,9 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => {
}

return (
<>
<div className="mt-10">
{message.status === MessageStatus.Stopped && (
<div key={message.id} className="mt-10 flex flex-col items-center">
<div key={message.id} className="flex flex-col items-center">
<span className="mb-3 text-center text-sm font-medium text-gray-500">
Oops! The generation was interrupted. Let&apos;s give it another go!
</span>
Expand All @@ -41,25 +44,47 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => {
</div>
)}
{message.status === MessageStatus.Error && (
<div
key={message.id}
className="flex flex-col items-center text-center text-sm font-medium text-gray-500"
>
<p>{`Apologies, something’s amiss!`}</p>
<p>
Jan’s in beta. Access&nbsp;
<span
className="cursor-pointer text-primary dark:text-blue-400"
onClick={() => setModalTroubleShooting(true)}
<>
{loadModelError === PORT_NOT_AVAILABLE ? (
<div
key={message.id}
className="flex flex-col items-center text-center text-sm font-medium text-gray-500 w-full"
>
troubleshooting assistance
</span>
&nbsp;now.
</p>
<ModalTroubleShooting />
</div>
<p className="w-[90%]">
Port 3928 is currently unavailable. Check for conflicting apps,
or access&nbsp;
<span
className="cursor-pointer text-primary dark:text-blue-400"
onClick={() => setModalTroubleShooting(true)}
>
troubleshooting assistance
</span>
&nbsp;for further support.
</p>
<ModalTroubleShooting />
</div>
) : (
<div
key={message.id}
className="flex flex-col items-center text-center text-sm font-medium text-gray-500"
>
<p>{`Apologies, something’s amiss!`}</p>
<p>
Jan’s in beta. Access&nbsp;
<span
className="cursor-pointer text-primary dark:text-blue-400"
onClick={() => setModalTroubleShooting(true)}
>
troubleshooting assistance
</span>
&nbsp;now.
</p>
<ModalTroubleShooting />
</div>
)}
</>
)}
</>
</div>
)
}
export default ErrorMessage

0 comments on commit 7fbc6cb

Please sign in to comment.