nsarrazin HF Staff commited on
Commit
ee5c213
·
unverified ·
1 Parent(s): c31c50e

fix(logs): better error logging

Browse files
src/lib/migrations/routines/06-trim-message-updates.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
  type MessageUpdate,
9
  } from "$lib/types/MessageUpdate";
10
  import type { Message } from "$lib/types/Message";
 
11
 
12
  // -----------
13
 
@@ -34,7 +35,7 @@ function convertMessageUpdate(message: Message, update: MessageUpdate): MessageU
34
 
35
  return update;
36
  } catch (error) {
37
- console.error("Error converting message update during migration. Skipping it... Error:", error);
38
  return null;
39
  }
40
  }
 
8
  type MessageUpdate,
9
  } from "$lib/types/MessageUpdate";
10
  import type { Message } from "$lib/types/Message";
11
+ import { logger } from "$lib/server/logger";
12
 
13
  // -----------
14
 
 
35
 
36
  return update;
37
  } catch (error) {
38
+ logger.error(error, "Error converting message update during migration. Skipping it..");
39
  return null;
40
  }
41
  }
src/lib/server/textGeneration/title.ts CHANGED
@@ -21,7 +21,7 @@ export async function* generateTitleForConversation(
21
  title,
22
  };
23
  } catch (cause) {
24
- console.error(Error("Failed whilte generating title for conversation", { cause }));
25
  }
26
  }
27
 
 
21
  title,
22
  };
23
  } catch (cause) {
24
+ logger.error(Error("Failed whilte generating title for conversation", { cause }));
25
  }
26
  }
27
 
src/lib/server/websearch/runWebSearch.ts CHANGED
@@ -18,6 +18,7 @@ import {
18
  } from "./update";
19
  import { mergeAsyncGenerators } from "$lib/utils/mergeAsyncGenerators";
20
  import { MetricsServer } from "../metrics";
 
21
 
22
  const MAX_N_PAGES_TO_SCRAPE = 8 as const;
23
  const MAX_N_PAGES_TO_EMBED = 5 as const;
@@ -86,7 +87,7 @@ export async function* runWebSearch(
86
  return webSearch;
87
  } catch (searchError) {
88
  const message = searchError instanceof Error ? searchError.message : String(searchError);
89
- console.error(message);
90
  yield makeErrorUpdate({ message: "An error occurred", args: [message] });
91
 
92
  const webSearch: WebSearch = {
 
18
  } from "./update";
19
  import { mergeAsyncGenerators } from "$lib/utils/mergeAsyncGenerators";
20
  import { MetricsServer } from "../metrics";
21
+ import { logger } from "$lib/server/logger";
22
 
23
  const MAX_N_PAGES_TO_SCRAPE = 8 as const;
24
  const MAX_N_PAGES_TO_EMBED = 5 as const;
 
87
  return webSearch;
88
  } catch (searchError) {
89
  const message = searchError instanceof Error ? searchError.message : String(searchError);
90
+ logger.error(message);
91
  yield makeErrorUpdate({ message: "An error occurred", args: [message] });
92
 
93
  const webSearch: WebSearch = {
src/lib/server/websearch/scrape/playwright.ts CHANGED
@@ -71,7 +71,7 @@ export async function withPage<T>(
71
  env.PLAYWRIGHT_ADBLOCKER === "true" && (await blocker.enableBlockingInPage(page));
72
 
73
  const res = await page.goto(url, { waitUntil: "load", timeout: 3500 }).catch(() => {
74
- console.warn(`Failed to load page within 2s: ${url}`);
75
  });
76
 
77
  // await needed here so that we don't close the context before the callback is done
 
71
  env.PLAYWRIGHT_ADBLOCKER === "true" && (await blocker.enableBlockingInPage(page));
72
 
73
  const res = await page.goto(url, { waitUntil: "load", timeout: 3500 }).catch(() => {
74
+ logger.warn(`Failed to load page within 2s: ${url}`);
75
  });
76
 
77
  // await needed here so that we don't close the context before the callback is done
src/routes/conversation/[id]/+server.ts CHANGED
@@ -23,6 +23,7 @@ import { usageLimits } from "$lib/server/usageLimits";
23
  import { MetricsServer } from "$lib/server/metrics";
24
  import { textGeneration } from "$lib/server/textGeneration";
25
  import type { TextGenerationContext } from "$lib/server/textGeneration/types";
 
26
 
27
  export async function POST({ request, locals, params, getClientAddress }) {
28
  const id = z.string().parse(params.id);
@@ -444,7 +445,7 @@ export async function POST({ request, locals, params, getClientAddress }) {
444
  status: MessageUpdateStatus.Error,
445
  message: (e as Error).message,
446
  });
447
- console.error(e);
448
  } finally {
449
  // check if no output was generated
450
  if (!hasError && messageToWriteTo.content === initialMessageContent) {
 
23
  import { MetricsServer } from "$lib/server/metrics";
24
  import { textGeneration } from "$lib/server/textGeneration";
25
  import type { TextGenerationContext } from "$lib/server/textGeneration/types";
26
+ import { logger } from "$lib/server/logger.js";
27
 
28
  export async function POST({ request, locals, params, getClientAddress }) {
29
  const id = z.string().parse(params.id);
 
445
  status: MessageUpdateStatus.Error,
446
  message: (e as Error).message,
447
  });
448
+ logger.error(e);
449
  } finally {
450
  // check if no output was generated
451
  if (!hasError && messageToWriteTo.content === initialMessageContent) {