// Advanced debugging skill for MyJKKN project. Specialized workflows for debugging Next.js 15, Supabase, React Query, TypeScript, and service layer issues. Includes automated analysis tools, common error patterns, and step-by-step troubleshooting guides for reducing debugging time. Use when investigating bugs, errors, performance issues, or unexpected behavior. (project)
| name | advanced-debugging |
| description | Advanced debugging skill for MyJKKN project. Specialized workflows for debugging Next.js 15, Supabase, React Query, TypeScript, and service layer issues. Includes automated analysis tools, common error patterns, and step-by-step troubleshooting guides for reducing debugging time. Use when investigating bugs, errors, performance issues, or unexpected behavior. (project) |
This skill provides specialized debugging workflows, tools, and knowledge for efficiently troubleshooting issues in the MyJKKN application. It covers the complete tech stack including Next.js 15, Supabase, React Query, TypeScript, and custom service layer patterns, significantly reducing time spent on debugging.
Use this skill when:
lib/services/_optimized variantsWhen encountering an issue, start with the automated analyzer:
# Analyze current application state
node scripts/debug-analyzer.js
# Analyze specific log file
node scripts/log-analyzer.js logs/app.log
# Test database connectivity and RLS
node scripts/db-query-tester.js
Follow the debugging workflow in references/debugging-workflows.md:
// Check React Query devtools
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
// Add to layout for debugging
<ReactQueryDevtools initialIsOpen={false} />
// Monitor component renders
useEffect(() => {
logger.dev('component-name', 'Component rendered', { props, state });
}, [props, state]);
// Check form validation errors
const { formState: { errors } } = useForm();
console.log('Form errors:', errors);
// Add debug logging to services
import { logger } from '@/lib/utils/enhanced-logger';
static async getData(filters: Filters) {
logger.dev('module/service', 'Fetching data', { filters });
try {
const { data, error } = await this.supabase
.from('table')
.select('*')
.eq('institution_id', filters.institutionId);
logger.dev('module/service', 'Query result', {
rowCount: data?.length,
hasError: !!error
});
if (error) {
logger.error('module/service', 'Query failed', error);
throw error;
}
return data;
} catch (error) {
logger.error('module/service', 'Unexpected error', error);
throw error;
}
}
// Test RLS policies
const { data, error } = await supabase
.from('table')
.select('*')
.eq('id', 'test-id');
console.log('RLS Test:', { data, error });
// Check current user
const { data: { user } } = await supabase.auth.getUser();
console.log('Current user:', user);
// Verify role and permissions
const { data: profile } = await supabase
.from('profiles')
.select('*')
.eq('id', user.id)
.single();
console.log('Profile:', profile);
Refer to references/common-issues.md for solutions to frequent problems:
Authentication Issues:
Performance Issues:
Build Errors:
See references/supabase-debugging.md for detailed Supabase troubleshooting:
Query Debugging:
// Enable query logging
const { data, error, status, statusText } = await supabase
.from('table')
.select('*')
.explain();
console.log('Query plan:', { data, error, status, statusText });
RLS Policy Testing:
-- Test as specific user
SET LOCAL role = 'authenticated';
SET LOCAL request.jwt.claim.sub = 'user-id-here';
SELECT * FROM table WHERE condition;
Connection Issues:
// Test connection with timeout
import { createClient WithTimeout } from '@/lib/supabase/client-with-timeout';
const supabase = createClientWithTimeout(5000); // 5 second timeout
Common React Query issues and solutions:
// Inspect query state
const { data, isLoading, isError, error, failureReason } = useQuery({
queryKey: ['key'],
queryFn: fetchData
});
console.log('Query state:', {
data,
isLoading,
isError,
error,
failureReason
});
// Force refetch
const { refetch } = useQuery({ ... });
refetch();
// Invalidate cache
queryClient.invalidateQueries({ queryKey: ['key'] });
// Reset query
queryClient.resetQueries({ queryKey: ['key'] });
TypeScript-specific debugging:
// Check inferred types
type InferredType = typeof variable;
// Hover over InferredType to see the actual type
// Use satisfies for type checking without assertion
const config = {
api: 'url',
timeout: 5000
} satisfies Config;
// Debug complex types
type Debug<T> = { [K in keyof T]: T[K] };
type DebuggableType = Debug<ComplexType>;
// Check assignability
const test: ExpectedType = actualValue; // Will error if not assignable
For debugging production issues:
// Production-safe logging
if (process.env.NODE_ENV === 'production') {
logger.error('module', 'Error occurred', {
userId: user.id,
timestamp: new Date().toISOString(),
error: error.message // Don't log full error in production
});
}
Location: lib/utils/enhanced-logger.ts
Features:
Usage:
import { logger } from '@/lib/utils/enhanced-logger';
logger.dev('module', 'Development log', data); // Dev only
logger.info('module', 'Info message', data); // Production
logger.warn('module', 'Warning message', data); // Production
logger.error('module', 'Error message', error); // Production
logger.debug('module', 'Debug message', data); // Dev only
debug-analyzer.js - Analyzes application state and configuration
node scripts/debug-analyzer.js
log-analyzer.js - Parses and analyzes log files
node scripts/log-analyzer.js logs/app.log --filter error
node scripts/log-analyzer.js logs/app.log --module billing
db-query-tester.js - Tests database queries and RLS policies
node scripts/db-query-tester.js --test-connection
node scripts/db-query-tester.js --test-rls table_name
Before diving deep, check these common issues:
Authentication:
Database:
React Query:
Service Layer:
UI/Components:
Build/Deploy:
Debugging Workflows: references/debugging-workflows.md
Common Issues: references/common-issues.md
Supabase Debugging: references/supabase-debugging.md
Performance Debugging: references/performance-debugging.md
# Development
npm run dev # Start dev server
npm run build # Test production build
npm run lint # Check linting errors
# Debugging
npm run clean # Clear Next.js cache
npm run clean:all # Clear all caches
# Testing
npx tsc --noEmit # Type check without building
lib/utils/enhanced-logger.ts # Logging utility
lib/supabase/client.ts # Supabase client
middleware.ts # Auth middleware
lib/services/ # Service layer
types/ # TypeScript types
app/(routes)/ # Page routes
NEXT_PUBLIC_SUPABASE_URL # Supabase project URL
NEXT_PUBLIC_SUPABASE_ANON_KEY # Supabase anon key
NEXT_PUBLIC_APP_VERSION # App version for caching
NODE_ENV # development | production
Version: 1.0.0 Last Updated: 2025-01-16 Maintained by: MyJKKN Development Team