Преглед на файлове

Improve product import error reporting and reduce batch size for debugging

- Server: wrap importProducts in try-catch, extract actual PG error from Drizzle
  error chain and throw clean TRPCError with meaningful message
- Client: reduce batch size from 500 to 50 rows for finer-grained progress
  and easier failure isolation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tony T преди 2 дни
родител
ревизия
a69c7dab52
променени са 2 файла, в които са добавени 11 реда и са изтрити 2 реда
  1. 1 1
      client/src/pages/DataSources.tsx
  2. 10 1
      server/routers.ts

+ 1 - 1
client/src/pages/DataSources.tsx

@@ -244,7 +244,7 @@ export default function DataSources() {
     }
 
     // ── Client-side batching with progress ─────────────────────────────
-    const BATCH = 500;
+    const BATCH = 50;
     const batches = Math.ceil(items.length / BATCH);
     setImportProgress({ current: 0, total: batches, status: "running" });
 

+ 10 - 1
server/routers.ts

@@ -1519,7 +1519,16 @@ Return ONLY the JSON array, no markdown or explanation.`,
       }))
       .mutation(async ({ input }) => {
         if (input.replaceAll) await deleteAllKnowledgeProducts();
-        return bulkCreateKnowledgeProducts(input.products);
+        try {
+          return await bulkCreateKnowledgeProducts(input.products);
+        } catch (err: any) {
+          const cause = err?.cause?.message || err?.cause?.toString() || "";
+          const msg   = err?.message || String(err);
+          // Extract the real PG error (after the SQL dump)
+          const pgErr = cause || msg.split("\n").filter(Boolean).pop() || msg;
+          console.error("[importProducts] DB error:", pgErr, "\nFull:", msg.substring(0, 500));
+          throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: `DB insert failed: ${pgErr}` });
+        }
       }),
   }),