From d07f6b4d099c695dd2a7860a0105400b5b812fde Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Sun, 18 May 2025 12:10:01 -0700 Subject: [PATCH] Remove debug statements --- embeddings/embeddings_service.py | 20 +------------------- src/app/api/auth/verify-session/route.ts | 3 +-- src/app/api/chat/route.ts | 4 ---- src/app/api/documents/process/route.ts | 12 ++---------- src/app/api/documents/route.ts | 17 +---------------- src/app/api/health/route.ts | 4 ++-- src/app/api/user/apikey/route.ts | 3 +-- src/app/page.tsx | 2 +- src/components/ChatInterface.tsx | 2 -- src/components/ChatSidebar.tsx | 3 ++- src/components/Dashboard.tsx | 10 +++++++++- src/components/EnhancedPDFViewer.tsx | 6 ------ src/components/ForgotPasswordForm.tsx | 2 ++ src/components/LogoutButton.tsx | 1 + src/lib/pgvector.ts | 2 -- 15 files changed, 23 insertions(+), 68 deletions(-) diff --git a/embeddings/embeddings_service.py b/embeddings/embeddings_service.py index 982b6de..ad7d40d 100644 --- a/embeddings/embeddings_service.py +++ b/embeddings/embeddings_service.py @@ -88,33 +88,15 @@ async def process_document_endpoint( file: UploadFile = File(...), document_id: str = Form(...) ): - print(f"\n\n--- New Processing Request ---") - print(f"Document ID: {document_id}") - print(f"Filename: {file.filename}") - print(f"Content type: {file.content_type}") - try: # First verify we can read the file - print("Attempting to read file...") - contents = await file.read() - print(f"Successfully read {len(contents)} bytes") await file.seek(0) # Rewind for actual processing # Now process the document - print("Starting document processing...") result = await process_document(file, document_id) - print("Document processing completed successfully") return result - except Exception as e: - import traceback - print("\n!!! ERROR OCCURRED !!!") - print(f"Error type: {type(e).__name__}") - print(f"Error message: {str(e)}") - print("Stack trace:") - traceback.print_exc() - print("!!! END OF ERROR !!!\n") - + except Exception as e: raise HTTPException( status_code=500, detail=f"Error processing document: {str(e)}" diff --git a/src/app/api/auth/verify-session/route.ts b/src/app/api/auth/verify-session/route.ts index 135fdb5..0132547 100644 --- a/src/app/api/auth/verify-session/route.ts +++ b/src/app/api/auth/verify-session/route.ts @@ -34,7 +34,6 @@ export async function GET(request: Request) { }) } catch (error) { - console.error('Session verification error:', error) - return NextResponse.json({ error: 'Internal server error' }, { status: 500 }) + return NextResponse.json({ error: error }, { status: 500 }) } } \ No newline at end of file diff --git a/src/app/api/chat/route.ts b/src/app/api/chat/route.ts index 150bede..efc586c 100644 --- a/src/app/api/chat/route.ts +++ b/src/app/api/chat/route.ts @@ -52,14 +52,10 @@ export async function POST(req: NextRequest) { user.apiKey ); - console.log(`Found ${relevantChunks.length} relevant chunks`); - if (!Array.isArray(relevantChunks)) { - console.warn("findSimilarChunks did not return an array"); relevantChunks = []; } } catch (error) { - console.error("Error retrieving similar chunks:", error instanceof Error ? error.message : String(error)); relevantChunks = []; // Log a more detailed error to help with debugging if (error instanceof Error) { diff --git a/src/app/api/documents/process/route.ts b/src/app/api/documents/process/route.ts index 313c898..f0bb6cf 100644 --- a/src/app/api/documents/process/route.ts +++ b/src/app/api/documents/process/route.ts @@ -11,8 +11,7 @@ const EMBEDDINGS_SERVICE_URL = process.env.EMBEDDINGS_SERVICE_URL || "http://loc export async function POST(req: NextRequest) { try { const { documentId } = await req.json(); - console.log('Starting document processing for documentId: ', documentId); - + // get document and user info const document = await prisma.document.findUnique({ where: { id: documentId }, @@ -46,9 +45,6 @@ export async function POST(req: NextRequest) { formData.append('file', pdfBlob, 'document.pdf'); formData.append('document_id', document.id); - // Send the PDF to the FastAPI service for processing - console.log('Sending PDF to FastAPI service for processing...'); - try { const processingResponse = await fetch(`${EMBEDDINGS_SERVICE_URL}/process-document`, { @@ -63,11 +59,9 @@ export async function POST(req: NextRequest) { // Get the processing results const processingResult = await processingResponse.json(); - console.log('Processing result:', processingResult); // Save document chunks to database using Prisma if (processingResult.chunks && processingResult.chunks.length > 0) { - console.log(`Saving ${processingResult.chunks.length} chunks to database...`); // Save each chunk to the database for (const chunk of processingResult.chunks) { @@ -101,7 +95,6 @@ export async function POST(req: NextRequest) { } } - console.log(`Document processing complete. Successfully processed ${processingResult.chunks_processed} chunks. Failed: ${processingResult.chunks_failed}`); return NextResponse.json({ success: true, message: 'Document processed successfully', @@ -114,9 +107,8 @@ export async function POST(req: NextRequest) { } } catch (error) { - console.error('Error processing document: ', error); return NextResponse.json( - { error: 'Failed to process document' }, + { error: error }, { status: 500 } ) } diff --git a/src/app/api/documents/route.ts b/src/app/api/documents/route.ts index 709700d..3afe93f 100644 --- a/src/app/api/documents/route.ts +++ b/src/app/api/documents/route.ts @@ -45,7 +45,6 @@ export async function POST(req: Request): Promise { } if(!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY || !process.env.S3_PDFBUCKET_NAME) { - console.error('Missing S3 credentials in environment variables'); return NextResponse.json( {error: 'Server configuration error: Missing S3 credentials'}, {status: 500} @@ -87,20 +86,7 @@ export async function POST(req: Request): Promise { body: JSON.stringify({documentId: document.id}), }); - console.log('Process Response:', processResponse); - - let responseData; - try { - const responseText = await processResponse.text(); - responseData = JSON.parse(responseText); - console.log('Process Response:', responseData); - } catch (error) { - console.error('Error parsing process response:', error); - console.error('Raw response: ', await processResponse.text()); - } - if (!processResponse.ok) { - console.error('Document processing failed with status:', processResponse.status); // Continue anyway, as processing can be retrieved later return NextResponse.json({ url: s3Result.url, @@ -118,7 +104,6 @@ export async function POST(req: Request): Promise { processingStatus: 'success' }); } catch (error) { - console.log(error); - return NextResponse.json({ error: 'An error occurred' }); + return NextResponse.json({ error: error }); } } \ No newline at end of file diff --git a/src/app/api/health/route.ts b/src/app/api/health/route.ts index 5db103b..aaee4ba 100644 --- a/src/app/api/health/route.ts +++ b/src/app/api/health/route.ts @@ -14,12 +14,12 @@ export async function GET() { version: process.env.npm_package_version || 'unknown' }); } catch (error) { - console.error('Health check failed:', error); return NextResponse.json( { status: 'error', message: 'Health check failed', - timestamp: new Date().toISOString() + timestamp: new Date().toISOString(), + error: error instanceof Error ? error.message : String(error) }, { status: 500 } ); diff --git a/src/app/api/user/apikey/route.ts b/src/app/api/user/apikey/route.ts index da2e2ef..dfa8b69 100644 --- a/src/app/api/user/apikey/route.ts +++ b/src/app/api/user/apikey/route.ts @@ -29,9 +29,8 @@ export async function POST(req: NextRequest) { }) return NextResponse.json({ message: 'API key updated successfully' }); } catch (error) { - console.error('Error updating API key: ', error); return NextResponse.json( - {error: 'Failed to update API key'}, + {error: error}, {status: 500} ) } diff --git a/src/app/page.tsx b/src/app/page.tsx index dc452d6..8ba5f85 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -20,9 +20,9 @@ export default function Home() { router.push('/login'); } } catch (error) { - console.error('Auth check error: ', error); // on error, redirect to login router.push('/login'); + console.error('Auth check error: ', error); } }; checkAuth(); diff --git a/src/components/ChatInterface.tsx b/src/components/ChatInterface.tsx index 6b13f0a..25fe630 100644 --- a/src/components/ChatInterface.tsx +++ b/src/components/ChatInterface.tsx @@ -66,7 +66,6 @@ export default function ChatInterface({ } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Failed to send message. Please try again.'; setError(errorMessage); - console.error('Error sending message: ', error); } finally { setIsLoading(false); } @@ -79,7 +78,6 @@ export default function ChatInterface({ } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Failed to start voice recording. Please try again.'; setError(errorMessage); - console.error('Error with voice recording: ', error); } } diff --git a/src/components/ChatSidebar.tsx b/src/components/ChatSidebar.tsx index c145169..104bec7 100644 --- a/src/components/ChatSidebar.tsx +++ b/src/components/ChatSidebar.tsx @@ -130,7 +130,8 @@ const ChatSidebar = forwardRef(({ onDeleteConversation(conversationId, documentId); } } catch (error) { - console.error('Error deleting conversation:', error); + //TODO: Display error message to user + console.error('Delete conversation error: ', error); alert('Failed to delete conversation'); } finally { setDeleting(null); diff --git a/src/components/Dashboard.tsx b/src/components/Dashboard.tsx index 57cea30..f6de1c9 100644 --- a/src/components/Dashboard.tsx +++ b/src/components/Dashboard.tsx @@ -78,7 +78,8 @@ function DashboardWithSearchParams () { // Update URL with the selected conversation updateUrl(convoId); } catch (error) { - console.error('Error loading conversations: ', error); + // TODO: Display error message to user + console.error('Error loading conversation: ', error); setError('Failed to load conversation'); } }, [conversationId, updateUrl]); @@ -93,6 +94,7 @@ function DashboardWithSearchParams () { router.push('/login') } } catch (error) { + // TODO: Display error message to user console.error('Auth check error: ', error); router.push('/login'); } @@ -109,9 +111,11 @@ function DashboardWithSearchParams () { if(response.ok) { setUserId(data.id); } else { + // TODO: Display error message to user console.error('Failed to fetch user: ', data); } } catch (error) { + // TODO: Display error message to user console.error('Error fetching user:', error); } }; @@ -152,6 +156,7 @@ function DashboardWithSearchParams () { await handleSelectConversation(chatId, matchingConversation.documentId); } } catch (error) { + // TODO: Display error message to user console.error('Error restoring conversations: ', error); setError('Failed to restore conversation from URL'); } finally { @@ -171,6 +176,7 @@ function DashboardWithSearchParams () { const data = await response.json(); return data.conversations; } catch (error) { + // TODO: Display error message to user console.error('Error fetching conversations: ', error); setError('Failed to fetch conversations'); return []; @@ -247,6 +253,7 @@ function DashboardWithSearchParams () { console.error('No conversationId returned from server'); } } catch (error) { + // TODO: Display error message to user console.error('Upload error:', error); setError('Failed to upload document'); } @@ -297,6 +304,7 @@ function DashboardWithSearchParams () { data.assistantMessage // Add assistant response ]); } catch (error) { + // TODO: Display error message to user console.error('Chat error: ', error); setError('Failed to send message'); } diff --git a/src/components/EnhancedPDFViewer.tsx b/src/components/EnhancedPDFViewer.tsx index a451629..fa0434d 100644 --- a/src/components/EnhancedPDFViewer.tsx +++ b/src/components/EnhancedPDFViewer.tsx @@ -1,5 +1,4 @@ // app/components/EnhancedPDFViewer.tsx - import { ChevronLeft, ChevronRight, Loader, Loader2, Upload } from "lucide-react"; import { useRef, useState } from "react"; import {Document, Page, pdfjs} from 'react-pdf'; @@ -8,11 +7,6 @@ import 'react-pdf/dist/Page/TextLayer.css'; // Initialize pdfjs worker pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.mjs`; -// pdfjs.GlobalWorkerOptions.workerSrc = new URL( -// "pdfjs-dist/build/pdf.worker.min.mjs", -// import.meta.url -// ).toString(); - interface EnhancedPDFViewerProps { currentPDF: string | null; onFileUpload: (e: React.ChangeEvent) => void; diff --git a/src/components/ForgotPasswordForm.tsx b/src/components/ForgotPasswordForm.tsx index 0a44293..0cc188f 100644 --- a/src/components/ForgotPasswordForm.tsx +++ b/src/components/ForgotPasswordForm.tsx @@ -40,6 +40,7 @@ export default function ForgotPasswordForm() { }, body: requestBody, }).catch(fetchError => { + // TODO: Display error message to user console.error('Fetch error:', fetchError); throw new Error('Network error occurred'); }); @@ -52,6 +53,7 @@ export default function ForgotPasswordForm() { setSuccess('If an account with that email exists, you will receive a password reset link.'); setEmail(''); } catch (error) { + // TODO: Display error message to user console.error('Password reset request error:', error); setError(error instanceof Error ? error.message : 'An error occurred'); } finally { diff --git a/src/components/LogoutButton.tsx b/src/components/LogoutButton.tsx index 9bdd2cf..d7ae789 100644 --- a/src/components/LogoutButton.tsx +++ b/src/components/LogoutButton.tsx @@ -27,6 +27,7 @@ export default function LogoutButton() { // Force a page refresh to clear any client-side state router.refresh(); } catch (error) { + // TODO: Display error message to user console.error('Logout error:', error); } finally { setIsLoading(false); diff --git a/src/lib/pgvector.ts b/src/lib/pgvector.ts index c76a49e..d5bec06 100644 --- a/src/lib/pgvector.ts +++ b/src/lib/pgvector.ts @@ -59,7 +59,6 @@ export async function getBatchEmbeddings(texts: string[]): Promise { const data = await response.json(); return data.embeddings; } catch (error) { - console.error("Error getting batch embeddings: ", error); throw error; } } @@ -88,7 +87,6 @@ export async function saveDocumentChunks(chunks: ChunkData[]) { } return {success: true, count: chunks.length}; } catch (error) { - console.error("Error saving document chunks: ", error); throw error; } }