Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

fix(workers): fix misleading error message when rss import fails to create bookmark. fixes #2838

Mohamed Bassem9651c79ca693
diff --git a/apps/mobile/components/bookmarks/card/TagList.tsx b/apps/mobile/components/bookmarks/card/TagList.tsx
index 1e35e54f..1fdba333 100644
--- a/apps/mobile/components/bookmarks/card/TagList.tsx
+++ b/apps/mobile/components/bookmarks/card/TagList.tsx
@@ -9,9 +9,9 @@ import TagPill from "../TagPill";
function TagListSkeleton() {
return (
- <View className="w-full">
- <Skeleton className="h-[18px] w-full rounded-full" />
- </View>
+ <View className="w-full">
+ <Skeleton className="h-[18px] w-full rounded-full" />
+ </View>
);
}
diff --git a/apps/workers/workers/feedWorker.ts b/apps/workers/workers/feedWorker.ts
index 9b8087e1..340eeff4 100644
--- a/apps/workers/workers/feedWorker.ts
+++ b/apps/workers/workers/feedWorker.ts
@@ -3,7 +3,9 @@ import { workerStatsCounter } from "metrics";
import { fetchWithProxy } from "network";
import cron from "node-cron";
import { buildImpersonatingTRPCClient } from "trpc";
+import { TRPCError } from "@trpc/server";
import { withWorkerEventLog, withWorkerTracing } from "workerTracing";
+import { ZodError } from "zod";
import type { ZFeedRequestSchema } from "@karakeep/shared-server";
import { db } from "@karakeep/db";
@@ -30,6 +32,29 @@ function getFeedMinuteOffset(feedId: string): number {
return Math.abs(hash) % 60;
}
+function getErrorMessage(error: unknown): string {
+ if (error instanceof TRPCError) {
+ if (error.cause instanceof ZodError) {
+ const validationMessage = error.cause.issues
+ .map((issue) => {
+ const path = issue.path.join(".");
+ return path ? `${path}: ${issue.message}` : issue.message;
+ })
+ .join("; ");
+
+ return `${error.code}: ${validationMessage}`;
+ }
+
+ return `${error.code}: ${error.message}`;
+ }
+
+ if (error instanceof Error) {
+ return error.message;
+ }
+
+ return String(error);
+}
+
export const FeedRefreshingWorker = cron.schedule(
"0 * * * *",
() => {
@@ -245,6 +270,28 @@ async function run(req: DequeuedJob<ZFeedRequestSchema>) {
}),
),
);
+ const bookmarkCreationFailures = createdBookmarks.flatMap((bookmark, idx) =>
+ bookmark.status === "rejected"
+ ? [{ item: newEntries[idx], reason: bookmark.reason }]
+ : [],
+ );
+ const createdBookmarkCount =
+ createdBookmarks.length - bookmarkCreationFailures.length;
+ addLogFields<"feedWorker.run">({
+ "feed.bookmarks_created": createdBookmarkCount,
+ "feed.bookmarks_failed": bookmarkCreationFailures.length,
+ });
+
+ if (bookmarkCreationFailures.length > 0) {
+ logger.warn(
+ `[feed][${jobId}] Failed to create ${bookmarkCreationFailures.length}/${newEntries.length} bookmarks from feed "${feed.name}" (${feed.id}).`,
+ );
+ for (const failure of bookmarkCreationFailures.slice(0, 3)) {
+ logger.debug(
+ `[feed][${jobId}] Bookmark creation failed for feed item "${failure.item.title ?? failure.item.guid}" (${failure.item.link}): ${getErrorMessage(failure.reason)}`,
+ );
+ }
+ }
// If importTags is enabled, attach categories as tags to the created bookmarks
if (feed.importTags) {
@@ -288,7 +335,7 @@ async function run(req: DequeuedJob<ZFeedRequestSchema>) {
.onConflictDoNothing();
logger.info(
- `[feed][${jobId}] Successfully imported ${newEntries.length} new enteries from feed "${feed.name}" (${feed.id}).`,
+ `[feed][${jobId}] Imported ${newEntries.length} feed entries from feed "${feed.name}" (${feed.id}); created ${createdBookmarkCount} bookmarks${bookmarkCreationFailures.length > 0 ? `, failed to create ${bookmarkCreationFailures.length}` : ""}.`,
);
return Promise.resolve();
diff --git a/packages/shared-server/src/eventLogTypes.ts b/packages/shared-server/src/eventLogTypes.ts
index 4da5fbf0..a7765a94 100644
--- a/packages/shared-server/src/eventLogTypes.ts
+++ b/packages/shared-server/src/eventLogTypes.ts
@@ -40,6 +40,8 @@ type EventLogInternal =
"feed.status_code"?: number;
"feed.items_found"?: number;
"feed.items_new"?: number;
+ "feed.bookmarks_created"?: number;
+ "feed.bookmarks_failed"?: number;
"feed.skipped_quota"?: boolean;
}
| {