-
Notifications
You must be signed in to change notification settings - Fork 111
fix: code quality and safety improvements #743
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,7 +84,8 @@ export const createMeetEvent = async (accessToken, eventDetails) => { | |
| }, | ||
| ); | ||
|
|
||
| const data = await response.json(); | ||
| if (!response.ok) throw new Error("Request failed"); | ||
| const data = await response.json(); | ||
|
Comment on lines
+87
to
+88
Contributor
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. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== files =="
git ls-files | rg 'app/src/lib/(CalendarService\.js|__tests__/CalendarService\.test\.js)$' || true
echo "== CalendarService outline =="
ast-grep outline app/src/lib/CalendarService.js || true
echo "== CalendarService relevant lines =="
sed -n '1,140p' app/src/lib/CalendarService.js
echo "== CalendarService tests relevant lines =="
sed -n '1,220p' app/src/lib/__tests__/CalendarService.test.js
echo "== fetch resolvers in tests =="
python3 - <<'PY'
from pathlib import Path
p=Path('app/src/lib/__tests__/CalendarService.test.js')
s=p.read_text()
for i,line in enumerate(s.splitlines(),1):
if 'mockResolvedValueOnce' in line or 'mockRejectedValueOnce' in line:
print(f"{i}: {line}")
PYRepository: roshankumar0036singh/Uni-Event Length of output: 8698 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== deterministic probe for response.ok guard behavior =="
python3 - <<'PY'
def read_error_mock_without_ok(body_error='API Failure'):
response = {
"ok": None,
"status": None,
"json": lambda: {"error": body_error}
}
try:
if not response["ok"]:
raise Exception("Request failed")
data = response["json"]()
return ("parsed", data)
except Exception as e:
return ("raised", str(e))
for body in ["API Failure", "Calendar Failure"]:
print({body: read_error_mock_without_ok(body)})
PYRepository: roshankumar0036singh/Uni-Event Length of output: 322 Update the calendar response mocks for the new Both failing calendar tests return mock responses without 🤖 Prompt for AI Agents |
||
|
|
||
| if (data.error) throw new Error(data.error.message); | ||
|
|
||
|
|
@@ -125,7 +126,8 @@ export const addToCalendar = async (accessToken, event) => { | |
| }, | ||
| ); | ||
|
|
||
| const data = await response.json(); | ||
| if (!response.ok) throw new Error("Request failed"); | ||
| const data = await response.json(); | ||
| if (data.error) throw new Error(data.error.message); | ||
| return data; | ||
| } catch (error) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,24 +52,4 @@ export const usePushNotifications = () => { | |
|
|
||
| useEffect(() => { | ||
| registerForPushNotificationsAsync().then(token => setExpoPushToken(token)); | ||
|
|
||
| notificationListener.current = Notifications.addNotificationReceivedListener( | ||
| notification => { | ||
| setNotification(notification); | ||
| }, | ||
| ); | ||
|
|
||
| responseListener.current = Notifications.addNotificationResponseReceivedListener( | ||
| response => { | ||
| logger.debug(response); | ||
| }, | ||
| ); | ||
|
|
||
| return () => { | ||
| Notifications.removeNotificationSubscription(notificationListener.current); | ||
| Notifications.removeNotificationSubscription(responseListener.current); | ||
| }; | ||
| }, []); | ||
|
|
||
| return { expoPushToken, notification }; | ||
| }; | ||
| .catch(err => console.error(err)) | ||
|
Contributor
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. 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Locate files =="
git ls-files | rg '(^|/)usePushNotifications\.js$|(^|/)AttendanceDashboard\.js$' || true
echo "== Show relevant slices with line numbers =="
for f in app/src/lib/usePushNotifications.js app/src/screens/AttendanceDashboard.js; do
if [ -f "$f" ]; then
echo "--- $f ($(wc -l < "$f") lines) ---"
sed -n '1,120p' "$f" | cat -n
else
echo "missing $f"
fi
done
echo "== Parse check with Node parser (read-only) =="
python3 - <<'PY'
from pathlib import Path
files = Path('app/src/lib/usePushNotifications.js').resolve(), Path('app/src/screens/AttendanceDashboard.js').resolve()
for p in files:
if p.exists():
print(p)
print(open(p, encoding='utf-8').read()[-1200:])
PYRepository: roshankumar0036singh/Uni-Event Length of output: 10110 🌐 Web query:
💡 Result: In the Firebase Modular SDK (v9+), the getDoc function returns a Promise that resolves to a DocumentSnapshot [1]. You can handle this operation using either the.then.catch pattern or async/await syntax [2][3]. Based on your query regarding AttendanceDashboard.js, the following implementation shows how to use getDoc with a promise chain and error handling: import { doc, getDoc } from "firebase/firestore"; // Assuming db and COLLECTIONS.EVENTS are defined correctly const docRef = doc(db, COLLECTIONS.EVENTS, eventId); getDoc(docRef).then((docSnap) => { if (docSnap.exists) { console.log("Document data:", docSnap.data); } else { console.log("No such document!"); } }).catch((error) => { console.error("Error getting document:", error); }); Key points for this implementation: 1. Document Reference: Use the doc function to create a reference to the specific document, passing the database instance, collection name, and document ID [2][4]. 2. Fetching: getDoc is an asynchronous operation that returns a Promise [1]. 3. Existence Check: Always check if the document exists using the.exists method on the returned snapshot before attempting to access its data with.data [2][5][6]. 4. Error Handling: The.catch block will capture errors related to the fetch operation, such as permission issues or network failures [2][3]. Alternatively, many developers prefer async/await for cleaner syntax: try { const docSnap = await getDoc(docRef); if (docSnap.exists) { console.log("Document data:", docSnap.data); } else { console.log("No such document!"); } } catch (error) { console.error("Error getting document:", error); } Citations:
🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== AttendanceDashboard remaining lines =="
sed -n '140,180p' app/src/screens/AttendanceDashboard.js | cat -n
echo "== usePushNotifications remaining lines =="
sed -n '50,70p' app/src/lib/usePushNotifications.js | cat -n
echo "== Deterministic JS parse probe for dangling catch syntax =="
node - <<'JS'
const snippet = `
registerForPushNotificationsAsync().then(token => setExpoPushToken(token));
.catch(err => console.error(err))
`;
try {
Function(snippet);
console.log("Parses as", true);
} catch (err) {
console.log("Parses as", false, err.message);
}
JSRepository: roshankumar0036singh/Uni-Event Length of output: 1732 Complete the broken promise chains and closures. Both changed files stop before the
🧰 Tools🪛 Biome (2.5.5)[error] 55-55: Expected a statement but instead found '.catch(err => console.error(err))'. (parse) [error] 55-55: expected (parse) 📍 Affects 2 files
🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: roshankumar0036singh/Uni-Event
Length of output: 13105
Restore the mock-user setup for protected flow tests.
app/cypress/e2e/critical_flows.cy.jsnow visits/without callingsetMockUser, so these assertions can run with no authenticated user state. CallglobalThis.setMockUser(...)aftercy.visit('/')or add another authenticated setup before the flow tests.🧰 Tools
🪛 Biome (2.5.5)
[error] 6-6: Expected a statement but instead found '.catch(err => console.error(err))'.
(parse)
[error] 6-6: expected
}but instead the file ends(parse)
🤖 Prompt for AI Agents
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: roshankumar0036singh/Uni-Event
Length of output: 7621
🏁 Script executed:
Repository: roshankumar0036singh/Uni-Event
Length of output: 551
Fix the malformed Cypress chain before merging.
Line 5 opens a
.then(win => {callback, but line 6 starts with.catch(...)instead of usingcatchinside that callback. ThebeforeEachanddescribeblocks are also not closed, so this spec cannot be parsed.Complete or remove the
cy.window()setup, then closebeforeEachanddescribe;.catchis not a command-chain API and should not attach here if command failures are being handled.🧰 Tools
🪛 Biome (2.5.5)
[error] 6-6: Expected a statement but instead found '.catch(err => console.error(err))'.
(parse)
[error] 6-6: expected
}but instead the file ends(parse)
🤖 Prompt for AI Agents
Source: Linters/SAST tools