janhq/jan · error

String(e)

Error message

String(e)

What it means

Wraps any failure from pluginFindSessionByModel (looking up the inference session for a model) into a generic Error with the stringified original error. The extension logs the original then rethrows so callers see a consistent error surface from getSessionByModel.

Solutions

  1. Verify the modelId is loaded (check getLoadedModels) before looking up its session.
  2. Check the engine process is running and the engine preset is fresh.
  3. Reload the model to recreate the session, then retry the lookup.
  4. Compare the thrown string against the logged original error for the true root cause.

Example fix

// before
} catch (e) {
  logger.error(e)
  throw new Error(String(e))
}
// after
} catch (e) {
  logger.error(e)
  throw new Error(`Failed to find session for model ${modelId}: ${e instanceof Error ? e.message : String(e)}`)
}
Defensive patterns

Strategy: try-catch

Validate before calling

const loaded = await getLoadedModels()
if (!loaded.includes(modelId)) throw new Error(`Model ${modelId} is not loaded`)

Type guard

null

Try / catch

try {
  const session = await getSessionByModel(modelId)
} catch (e) {
  logger.warn(`No session for ${modelId}: ${e}`)
  const session = await loadModelThenGetSession(modelId) // fallback: load first
}

Prevention

When it happens

Trigger: pluginFindSessionByModel throws — e.g. the plugin/session registry rejects because no session exists for the modelId, the engine subprocess is down, or the IPC call to the engine fails.

Common situations: Querying a session for a model that was never loaded; the llamacpp engine process crashed or restarted; modelId casing/ID mismatch versus what was registered.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of janhq/jan@7205d770c1 (2026-09-17). Data as JSON: /api/errors/082a886158797c46. Report an issue: GitHub.

Appendix: source

Thrown at extensions/llamacpp-extension/src/index.ts:2491

            logger.error('Error parsing JSON from stream or server error:', e)
            // re‑throw so the async iterator terminates with an error
            throw e
          }
        }
      }
    } finally {
      reader.releaseLock()
    }
  }

  private async findSessionByModel(
    modelId: string
  ): Promise<SessionInfo | null> {
    try {
      return await pluginFindSessionByModel(modelId)
    } catch (e) {
      logger.error(e)
      throw new Error(String(e))
    }
  }

  private async ensureHealthySession(modelId: string): Promise<SessionInfo> {
    return pluginEnsureSessionReady(modelId, false)
  }

  override async chat(
    opts: chatCompletionRequest,
    abortController?: AbortController
  ): Promise<chatCompletion | AsyncIterable<chatCompletionChunk>> {
    const sessionInfo = await this.ensureHealthySession(opts.model)
    const baseUrl = `http://localhost:${sessionInfo.port}/v1`
    const url = `${baseUrl}/chat/completions`
    const headers = {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${sessionInfo.api_key}`,
    }

View on GitHub (pinned to 7205d770c1)