Skip to content

Commit 3bbfc5f

Browse files
authored
Merge branch 'develop' into Jatin-Issue#3470
2 parents 4af334c + c8fba25 commit 3bbfc5f

File tree

2 files changed

+61
-21
lines changed

2 files changed

+61
-21
lines changed

client/modules/IDE/hooks/useHandleMessageEvent.js

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,64 @@ import { stopSketch, expandConsole } from '../actions/ide';
66
export default function useHandleMessageEvent() {
77
const dispatch = useDispatch();
88

9+
const safeStringify = (
10+
obj,
11+
depth = 0,
12+
maxDepth = 10,
13+
seen = new WeakMap()
14+
) => {
15+
if (typeof obj !== 'object' || obj === null) return obj;
16+
17+
if (depth >= maxDepth) {
18+
if (seen.has(obj)) return '[Circular Reference]';
19+
}
20+
21+
seen.set(obj, true);
22+
23+
return Array.isArray(obj)
24+
? obj.map((item) => safeStringify(item, depth + 1, maxDepth, seen))
25+
: Object.fromEntries(
26+
Object.entries(obj).map(([key, value]) => [
27+
key,
28+
safeStringify(value, depth + 1, maxDepth, seen)
29+
])
30+
);
31+
};
32+
933
const handleMessageEvent = (data) => {
34+
if (!data || typeof data !== 'object') return;
1035
const { source, messages } = data;
11-
if (source === 'sketch' && Array.isArray(messages)) {
12-
const decodedMessages = messages.map((message) => Decode(message.log));
13-
decodedMessages.every((message, index, arr) => {
14-
const { data: args } = message;
15-
let hasInfiniteLoop = false;
16-
Object.keys(args).forEach((key) => {
17-
if (
18-
typeof args[key] === 'string' &&
19-
args[key].includes('Exiting potential infinite loop')
20-
) {
21-
dispatch(stopSketch());
22-
dispatch(expandConsole());
23-
hasInfiniteLoop = true;
24-
}
25-
});
26-
if (hasInfiniteLoop) {
27-
return false;
28-
}
29-
return true;
30-
});
31-
dispatch(dispatchConsoleEvent(decodedMessages));
36+
if (source !== 'sketch' || !Array.isArray(messages)) return;
37+
38+
const decodedMessages = messages.map((message) => {
39+
try {
40+
const decoded = Decode(message.log) ?? '[Unknown Message]'; // Ensure decoding works
41+
return safeStringify(decoded);
42+
} catch (error) {
43+
console.error('Error decoding message:', error);
44+
return { error: 'Failed to decode message' };
45+
}
46+
});
47+
48+
// Detect infinite loop warnings
49+
const hasInfiniteLoop = decodedMessages.some(
50+
(message) =>
51+
message?.data &&
52+
Object.values(message.data).some(
53+
(arg) =>
54+
typeof arg === 'string' &&
55+
arg.includes('Exiting potential infinite loop')
56+
)
57+
);
58+
59+
if (hasInfiniteLoop) {
60+
dispatch(stopSketch());
61+
dispatch(expandConsole());
62+
return;
3263
}
64+
65+
dispatch(dispatchConsoleEvent(decodedMessages));
3366
};
67+
3468
return handleMessageEvent;
3569
}

contributor_docs/installation.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Follow these instructions to set up your development environment, which you need to do before you start contributing code to this project.
44

5+
There are two ways to install the project locally:
6+
7+
Manual Installation is great if you're comfortable managing dependencies like Node.js and MongoDB directly on your machine. It's more hands-on and gives you finer control, which can be helpful for debugging or learning how each part works.
8+
9+
Docker Installation is ideal if you want a faster setup with all dependencies (Node, MongoDB, etc.) isolated in containers. This avoids version conflicts and works consistently across environments especially helpful if you're new to backend setup or don't want to alter your local setup.
10+
511
## Manual Installation
612

713
_Note_: The installation steps assume you are using a Unix-like shell. If you are using Windows, you will need to use `copy` instead of `cp`.

0 commit comments

Comments
 (0)