Skip to content

fix: add missing returns in controller#402

Merged
aryandas2911 merged 3 commits into
aryandas2911:mainfrom
yuvraj-k-singh:fix/missing-return-statement
May 18, 2026
Merged

fix: add missing returns in controller#402
aryandas2911 merged 3 commits into
aryandas2911:mainfrom
yuvraj-k-singh:fix/missing-return-statement

Conversation

@yuvraj-k-singh
Copy link
Copy Markdown

📌 Description

This PR resolves a critical backend runtime crash where the server throws a "Cannot set headers after they are sent" error. By adding missing return statements to various controller guard clauses, we ensure that Express immediately exits the function after sending an error or validation response, preventing any subsequent code or duplicate responses from executing.

Additionally, an Express syntax bug in the routine creation response payload was resolved to ensure proper frontend integration.

🔗 Related Issue

Closes #17

🛠 Changes Made

backend/controllers/taskController.js

  • Added explicit return keywords before res.status().json() calls across all guard clauses and validation checks in createTask, getTasks, updateTask, and deleteTask.
  • Ensured absolute prevention of downstream execution post-response in the event of missing details or invalid authentication tokens.

backend/controllers/routineController.js

  • Added explicit return keywords to guard clauses in getRoutines and deleteRoutine to align with the acceptance criteria.
  • Fixed an Express syntax error in createRoutine where newRoutine was passed as a secondary argument to .json(). Rewrote it to properly bundle newRoutine inside a single unified response object ({ success: true, message: "...", routine: newRoutine }).

Codebase Audit

  • Thoroughly audited authController.js to verify it already complies with the proper guard-clause exit patterns.

📸 Screenshots (if applicable)

N/A (Backend logic and syntax architectural fixes only; no UI modifications).

✅ Checklist

  • Code runs locally
  • Followed project structure
  • No console errors
  • Properly tested changes
  • Linked the issue

🚀 Notes for Reviewers

  • Please specifically review the updated JSON payload formatting inside createRoutine (routineController.js) to ensure it seamlessly aligns with what the frontend context expects.
  • All HTTP status codes (200, 201, 400, 401, 404, 500) remain perfectly intact and unaltered.

@yuvraj-k-singh
Copy link
Copy Markdown
Author

Hi @aryandas2911 ,

I have submitted this PR to address the runtime crash caused by missing return statements in the controller guard clauses, as outlined in the issue tracker. I also cleaned up a minor JSON argument syntax bug in createRoutine.

The changes have been tested locally and ensure that the server no longer throws the "Cannot set headers after they are sent" error. Everything follows the project structure and is ready for your review.

Could you please take a look when you have a moment? Thank you! 🙌

@aryandas2911 aryandas2911 merged commit 77dc046 into aryandas2911:main May 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix missing 'return' statements in Backend Controllers

2 participants