Skip to content

Commit 889d157

Browse files
committed
dont do cursed console.group removal
1 parent f4bf611 commit 889d157

3 files changed

Lines changed: 47 additions & 41 deletions

File tree

src/lib/errorhandling/apiErrorHandling.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '$lib/typeguards/errorGuards';
99
import { toast } from 'svelte-sonner';
1010
import { isValidationError as isValidationProblem } from './ValidationProblemDetails';
11+
import { dev } from '$app/environment';
1112

1213
export type HandleProblemCallback = (problem: ProblemDetails) => boolean;
1314

@@ -34,27 +35,29 @@ async function handleResponseError(
3435
return null;
3536
}
3637

37-
console.groupCollapsed(`%cAPI Error: ${problem.title}`, 'color: red; font-weight: bold;');
38-
console.log('%cType: ', 'font-weight: bold;', problem.type);
39-
console.log('%cStatus: ', 'font-weight: bold;', problem.status);
40-
console.log('%cRequest ID:', 'font-weight: bold;', problem.requestId);
41-
if (problem.detail) {
42-
console.log('%cDetail: ', 'font-style: italic;', problem.detail);
43-
}
44-
if (isValidationProblem(problem)) {
45-
// nicely tabulate the field errors
46-
console.groupCollapsed('%cField errors', 'font-style: italic;');
47-
for (const [field, messages] of Object.entries(problem.errors)) {
48-
console.group(`${field}`);
49-
messages.forEach((msg) => console.log(`• ${msg}`));
50-
console.groupEnd();
38+
if (dev) {
39+
console.groupCollapsed(`%cAPI Error: ${problem.title}`, 'color: red; font-weight: bold;');
40+
console.log('%cType: ', 'font-weight: bold;', problem.type);
41+
console.log('%cStatus: ', 'font-weight: bold;', problem.status);
42+
console.log('%cRequest ID:', 'font-weight: bold;', problem.requestId);
43+
if (problem.detail) {
44+
console.log('%cDetail: ', 'font-style: italic;', problem.detail);
45+
}
46+
if (isValidationProblem(problem)) {
47+
// nicely tabulate the field errors
48+
console.groupCollapsed('%cField errors', 'font-style: italic;');
49+
for (const [field, messages] of Object.entries(problem.errors)) {
50+
console.group(`${field}`);
51+
messages.forEach((msg) => console.log(`• ${msg}`));
52+
console.groupEnd();
53+
}
54+
console.groupEnd(); // end Field errors
5155
}
52-
console.groupEnd(); // end Field errors
56+
// allow peeking at the full object if you need it
57+
console.log('%cFull payload:', 'font-weight: normal;', problem);
58+
console.trace();
59+
console.groupEnd();
5360
}
54-
// allow peeking at the full object if you need it
55-
console.log('%cFull payload:', 'font-weight: normal;', problem);
56-
console.trace();
57-
console.groupEnd();
5861

5962
if (handleProblemCallback && handleProblemCallback(problem)) return;
6063

src/lib/signalr/handlers/Log.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { isControlLogSender } from '$lib/signalr/models/ControlLogSender';
33
import { TriggerEvent } from '$lib/stores/ShockEventListenerStore';
44
import { toast } from 'svelte-sonner';
55
import { ControlType } from '../models/ControlType';
6+
import { dev } from '$app/environment';
67

78
export function handleSignalrLog(sender: unknown, logs: unknown) {
89
if (!isControlLogSender(sender) || !Array.isArray(logs) || !logs.every(isControlLog)) {
@@ -11,31 +12,33 @@ export function handleSignalrLog(sender: unknown, logs: unknown) {
1112
return;
1213
}
1314

14-
console.groupCollapsed(`SignalR Log from ${sender.customName ?? sender.name} (${sender.id})`);
15-
console.log(`Connection ID: ${sender.connectionId}`);
15+
if (dev) {
16+
console.groupCollapsed(`SignalR Log from ${sender.customName ?? sender.name} (${sender.id})`);
17+
console.log(`Connection ID: ${sender.connectionId}`);
1618

17-
// Log any additional custom items
18-
if (Object.keys(sender.additionalItems).length > 0) {
19-
console.group('Additional Items');
20-
for (const [key, value] of Object.entries(sender.additionalItems)) {
21-
console.log(`${key}:`, value);
19+
// Log any additional custom items
20+
if (Object.keys(sender.additionalItems).length > 0) {
21+
console.group('Additional Items');
22+
for (const [key, value] of Object.entries(sender.additionalItems)) {
23+
console.log(`${key}:`, value);
24+
}
25+
console.groupEnd();
2226
}
23-
console.groupEnd();
24-
}
2527

26-
// Iterate through each control log
27-
logs.forEach((log, index) => {
28-
console.group(`Log #${index + 1} - ${new Date(log.executedAt).toLocaleString()}`);
29-
console.log('Shocker:', `${log.shocker.name} (${log.shocker.id})`);
30-
console.log('Type:', ControlType[log.type]);
31-
if (log.type !== ControlType.Stop) {
32-
console.log('Intensity:', log.intensity);
33-
console.log('Duration (ms):', log.duration);
34-
}
35-
console.groupEnd();
36-
});
28+
// Iterate through each control log
29+
logs.forEach((log, index) => {
30+
console.group(`Log #${index + 1} - ${new Date(log.executedAt).toLocaleString()}`);
31+
console.log('Shocker:', `${log.shocker.name} (${log.shocker.id})`);
32+
console.log('Type:', ControlType[log.type]);
33+
if (log.type !== ControlType.Stop) {
34+
console.log('Intensity:', log.intensity);
35+
console.log('Duration (ms):', log.duration);
36+
}
37+
console.groupEnd();
38+
});
3739

38-
console.groupEnd();
40+
console.groupEnd();
41+
}
3942

4043
logs.forEach((log) => {
4144
TriggerEvent(log.shocker.id, log.type, log.duration, log.intensity);

vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default defineConfig(async ({ command, mode, isPreview }) => {
103103
legalComments: 'none',
104104
banner: '/*! For licenses information, see LICENSES.txt */',
105105
drop: mode === 'production' ? ['debugger'] : [],
106-
pure: mode === 'production' ? ['console.log', 'console.debug', 'console.group', 'console.groupCollapsed', 'console.groupEnd'] : [],
106+
pure: mode === 'production' ? ['console.log', 'console.debug'] : [],
107107
},
108108
});
109109
});

0 commit comments

Comments
 (0)