mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-10 16:22:38 +02:00
fix: gate console.log calls behind development check
Wraps unguarded console.log statements in use-connectors-electric, mcp-config-validator, and ElectricProvider behind an IS_DEV guard, matching the existing pattern in lib/electric/client.ts. Keeps console.error calls untouched so real errors still surface. Fixes #904
This commit is contained in:
parent
5da2d95d80
commit
b240057c61
3 changed files with 14 additions and 8 deletions
|
|
@ -33,6 +33,8 @@ import { z } from "zod";
|
||||||
import type { MCPServerConfig, MCPToolDefinition } from "@/contracts/types/mcp.types";
|
import type { MCPServerConfig, MCPToolDefinition } from "@/contracts/types/mcp.types";
|
||||||
import { connectorsApiService } from "@/lib/apis/connectors-api.service";
|
import { connectorsApiService } from "@/lib/apis/connectors-api.service";
|
||||||
|
|
||||||
|
const IS_DEV = process.env.NODE_ENV === "development";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zod schema for MCP server configuration
|
* Zod schema for MCP server configuration
|
||||||
* Supports both stdio (local process) and HTTP (remote server) transports
|
* Supports both stdio (local process) and HTTP (remote server) transports
|
||||||
|
|
@ -102,11 +104,11 @@ export const parseMCPConfig = (configJson: string): MCPConfigValidationResult =>
|
||||||
// Check cache first
|
// Check cache first
|
||||||
const cached = configCache.get(configJson);
|
const cached = configCache.get(configJson);
|
||||||
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
|
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
|
||||||
console.log("[MCP Validator] ✅ Using cached config");
|
if (IS_DEV) console.log("[MCP Validator] ✅ Using cached config");
|
||||||
return { config: cached.config, error: null };
|
return { config: cached.config, error: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("[MCP Validator] 🔍 Parsing new config...");
|
if (IS_DEV) console.log("[MCP Validator] 🔍 Parsing new config...");
|
||||||
|
|
||||||
// Clean up expired cache entries periodically
|
// Clean up expired cache entries periodically
|
||||||
if (configCache.size > 100) {
|
if (configCache.size > 100) {
|
||||||
|
|
@ -176,7 +178,7 @@ export const parseMCPConfig = (configJson: string): MCPConfigValidationResult =>
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[MCP Validator] ✅ Config parsed successfully:", config);
|
if (IS_DEV) console.log("[MCP Validator] ✅ Config parsed successfully:", config);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
config,
|
config,
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ import {
|
||||||
} from "@/lib/electric/client";
|
} from "@/lib/electric/client";
|
||||||
import { ElectricContext } from "@/lib/electric/context";
|
import { ElectricContext } from "@/lib/electric/context";
|
||||||
|
|
||||||
|
const IS_DEV = process.env.NODE_ENV === "development";
|
||||||
|
|
||||||
interface ElectricProviderProps {
|
interface ElectricProviderProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +42,7 @@ export function ElectricProvider({ children }: ElectricProviderProps) {
|
||||||
// No user logged in - cleanup if previous user existed
|
// No user logged in - cleanup if previous user existed
|
||||||
if (!isUserLoaded || !user?.id) {
|
if (!isUserLoaded || !user?.id) {
|
||||||
if (previousUserIdRef.current && isElectricInitialized()) {
|
if (previousUserIdRef.current && isElectricInitialized()) {
|
||||||
console.log("[ElectricProvider] User logged out, cleaning up...");
|
if (IS_DEV) console.log("[ElectricProvider] User logged out, cleaning up...");
|
||||||
cleanupElectric().then(() => {
|
cleanupElectric().then(() => {
|
||||||
previousUserIdRef.current = null;
|
previousUserIdRef.current = null;
|
||||||
setElectricClient(null);
|
setElectricClient(null);
|
||||||
|
|
@ -61,14 +63,14 @@ export function ElectricProvider({ children }: ElectricProviderProps) {
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
try {
|
try {
|
||||||
console.log(`[ElectricProvider] Initializing for user: ${userId}`);
|
if (IS_DEV) console.log(`[ElectricProvider] Initializing for user: ${userId}`);
|
||||||
const client = await initElectric(userId);
|
const client = await initElectric(userId);
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
previousUserIdRef.current = userId;
|
previousUserIdRef.current = userId;
|
||||||
setElectricClient(client);
|
setElectricClient(client);
|
||||||
setError(null);
|
setError(null);
|
||||||
console.log(`[ElectricProvider] ✅ Ready for user: ${userId}`);
|
if (IS_DEV) console.log(`[ElectricProvider] ✅ Ready for user: ${userId}`);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("[ElectricProvider] Failed to initialize:", err);
|
console.error("[ElectricProvider] Failed to initialize:", err);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import type { SearchSourceConnector } from "@/contracts/types/connector.types";
|
||||||
import type { SyncHandle } from "@/lib/electric/client";
|
import type { SyncHandle } from "@/lib/electric/client";
|
||||||
import { useElectricClient } from "@/lib/electric/context";
|
import { useElectricClient } from "@/lib/electric/context";
|
||||||
|
|
||||||
|
const IS_DEV = process.env.NODE_ENV === "development";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook for managing connectors with Electric SQL real-time sync
|
* Hook for managing connectors with Electric SQL real-time sync
|
||||||
*
|
*
|
||||||
|
|
@ -72,7 +74,7 @@ export function useConnectorsElectric(searchSpaceId: number | string | null) {
|
||||||
|
|
||||||
async function startSync() {
|
async function startSync() {
|
||||||
try {
|
try {
|
||||||
console.log("[useConnectorsElectric] Starting sync for search space:", searchSpaceId);
|
if (IS_DEV) console.log("[useConnectorsElectric] Starting sync for search space:", searchSpaceId);
|
||||||
|
|
||||||
const handle = await electricClient.syncShape({
|
const handle = await electricClient.syncShape({
|
||||||
table: "search_source_connectors",
|
table: "search_source_connectors",
|
||||||
|
|
@ -80,7 +82,7 @@ export function useConnectorsElectric(searchSpaceId: number | string | null) {
|
||||||
primaryKey: ["id"],
|
primaryKey: ["id"],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[useConnectorsElectric] Sync started:", {
|
if (IS_DEV) console.log("[useConnectorsElectric] Sync started:", {
|
||||||
isUpToDate: handle.isUpToDate,
|
isUpToDate: handle.isUpToDate,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue