-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtestErrorLogging.js
More file actions
70 lines (57 loc) · 1.76 KB
/
testErrorLogging.js
File metadata and controls
70 lines (57 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// testErrorLogging.js
// Load .env: try multiple likely locations (script dir, project root, process.cwd())
const path = require('path');
const dotenv = require('dotenv');
const tryPaths = [
path.resolve(__dirname, '.env'),
path.resolve(__dirname, '..', '.env'),
path.resolve(process.cwd(), '.env')
];
let loaded = false;
for (const p of tryPaths) {
try {
const result = dotenv.config({ path: p });
if (result.parsed) {
console.log(`Loaded .env from ${p}`);
loaded = true;
break;
}
} catch (e) {
// ignore
}
}
if (!loaded) {
console.warn('Warning: .env not found in standard locations; relying on process.env');
}
// Delay requiring the service until after env is (attempted) loaded to avoid early Supabase client initialization errors
const errorLogService = require('./services/errorLogService');
async function testErrorLogging() {
console.log('🧪 Testing Error Logging...');
// Check if environment variables are loaded
if (!process.env.SUPABASE_URL) {
console.error('❌ SUPABASE_URL not found in environment variables');
return;
}
// Testing basic error logging
const testError = new Error('Test error logging');
testError.code = 'TEST_ERROR';
try {
await errorLogService.logError({
error: testError,
category: 'info',
type: 'system'
});
console.log('✅ Basic error logging test passed');
// Testing critical error alerting
const criticalError = new Error('Critical test error');
await errorLogService.logError({
error: criticalError,
category: 'critical',
type: 'system'
});
console.log('✅ Critical error logging test passed');
} catch (error) {
console.error('❌ Test failed:', error);
}
}
testErrorLogging();