Skip to content

Latest commit

 

History

History
28 lines (22 loc) · 1.3 KB

Debugging_With_Copilot.md

File metadata and controls

28 lines (22 loc) · 1.3 KB

Bugs Identified

  • Weak validation:
    • No email format check.
    • No length limits on Name or Email.
    • No duplicate email check.
  • No explicit handling for a null user object in validation.
  • No protection against unexpected exceptions that could crash the API.

Fixes Implemented

  • Added regex-based email format validation.
  • Added length limits: Name ≤ 100 chars, Email ≤ 150 chars.
  • Added duplicate email check (case-insensitive) returning 400 with "Email is already in use."
  • Centralized validation logic in the ValidateUser method.
  • Wrapped each endpoint in try/catch to handle unexpected exceptions and return HTTP 500 with a generic message.

How Copilot Streamlined Debugging

  • Analyzed UsersController and highlighted validation and error-handling gaps.
  • Generated the regex pattern for email validation and suggested the structure of the ValidateUser method.
  • Produced updated controller code with try/catch blocks around each endpoint to prevent unhandled exceptions.
  • Helped design test cases for:
    • Invalid input (missing name/email, bad email format).
    • Duplicate emails.
    • Requests for non-existent user IDs (404 handling).

As a result, the API now validates user data more robustly, handles errors gracefully, and returns clear, appropriate HTTP status codes.