-
Notifications
You must be signed in to change notification settings - Fork 160
fix unsafe error #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Devnil434
wants to merge
3
commits into
AOSSIE-Org:main
from
Devnil434:bug/App-crashes-due-to-unsafe-access-on-null-values
Closed
fix unsafe error #147
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| server: | ||
| port: 1313 # The port number your backend server will run on | ||
|
|
||
| database: | ||
| uri: "mongodb://localhost:27017" | ||
| # Replace with your MongoDB Atlas connection string | ||
| # Get this from your MongoDB Atlas dashboard after creating a cluster and database | ||
|
|
||
| gemini: | ||
| apiKey: "<YOUR_GEMINI_API_KEY>" | ||
| # API key for OpenAI / Gemini model access | ||
| # Obtain from your OpenRouter.ai or OpenAI account dashboard | ||
|
|
||
| jwt: | ||
| secret: "<YOUR_JWT_SECRET>" | ||
| # A secret string used to sign JWT tokens | ||
| # Generate a strong random string (e.g. use `openssl rand -hex 32`) | ||
|
|
||
| expiry: 1440 | ||
| # Token expiry time in minutes (e.g. 1440 = 24 hours) | ||
|
|
||
| smtp: | ||
| host: "smtp.gmail.com" | ||
| # SMTP server host for sending emails (example is Gmail SMTP) | ||
|
|
||
| port: 587 | ||
| # SMTP server port (587 for TLS) | ||
|
|
||
| username: "<YOUR_EMAIL_ADDRESS>" | ||
| # Email username (your email address) | ||
|
|
||
| password: "<YOUR_EMAIL_PASSWORD_OR_APP_PASSWORD>" | ||
| # Password for the email or app-specific password if 2FA is enabled | ||
|
|
||
| senderEmail: "<YOUR_EMAIL_ADDRESS>" | ||
| # The 'from' email address used when sending mails | ||
|
|
||
| senderName: "DebateAI Team" | ||
|
|
||
| googleOAuth: | ||
| clientID: "<YOUR_GOOGLE_OAUTH_CLIENT_ID>" | ||
| # Google OAuth Client ID for OAuth login | ||
| # Obtain from Google Cloud Console (APIs & Services > Credentials > OAuth 2.0 Client IDs) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -282,9 +282,17 @@ const Game: React.FC = () => { | |
| ws.onopen = () => console.log("WebSocket connection established"); | ||
| ws.onmessage = (event) => { | ||
| try { | ||
| handleWebSocketMessage(JSON.parse(event.data)); | ||
| const raw = event.data; | ||
| let parsed: any = null; | ||
| try { | ||
| parsed = JSON.parse(typeof raw === 'string' ? raw : String(raw)); | ||
| } catch (err) { | ||
| console.warn('Game: failed to parse WS message', err); | ||
| return; | ||
| } | ||
| handleWebSocketMessage(parsed); | ||
| } catch (error) { | ||
| console.error("Failed to parse WebSocket message:", error); | ||
| console.error("Failed to handle WebSocket message:", error); | ||
| } | ||
|
Comment on lines
283
to
296
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Use the safeParse utility for consistency. This manual parsing logic duplicates the functionality of the
🔎 Recommended refactor+import { safeParse } from '@/utils/safeParse';
+
ws.onmessage = (event) => {
try {
- const raw = event.data;
- let parsed: any = null;
- try {
- parsed = JSON.parse(typeof raw === 'string' ? raw : String(raw));
- } catch (err) {
- console.warn('Game: failed to parse WS message', err);
- return;
- }
- handleWebSocketMessage(parsed);
+ const parsed = safeParse(event.data, null);
+ if (!parsed) return;
+ handleWebSocketMessage(parsed);
} catch (error) {
console.error("Failed to handle WebSocket message:", error);
}
};🤖 Prompt for AI Agents |
||
| }; | ||
| ws.onerror = (error) => console.error("WebSocket error:", error); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.