Skip to content

fix : added error handling and input validation to trackActivity utility - #4

Open
tmdeveloper007 wants to merge 1 commit into
syedahmedkhaderi:mainfrom
tmdeveloper007:activity-util-fix
Open

fix : added error handling and input validation to trackActivity utility#4
tmdeveloper007 wants to merge 1 commit into
syedahmedkhaderi:mainfrom
tmdeveloper007:activity-util-fix

Conversation

@tmdeveloper007

Copy link
Copy Markdown

Closes (upstream issues disabled — no issue created).

Summary of What Has Been Done:
Added input validation and comprehensive error handling to the trackActivity utility in lib/activity.js. The function previously had no validation on userId or type parameters and no try/catch, meaning invalid inputs or database errors would cause unhandled promise rejections silently. Now the function validates that userId and type are non-empty strings before making any database calls, wraps all Supabase operations in try/catch, and logs errors gracefully instead of crashing.

Changes Made:

  • lib/activity.js: add input validation, try/catch around all async operations, explicit error logging
  • security-tests/activity-util.test.cjs: new file covering all validation branches

Impact it Made:

  • Prevents unhandled promise rejections from trackActivity calls with bad inputs
  • Provides warning logs for invalid inputs instead of crashing the calling component
  • Adds test coverage for the validation logic

Note: Please assign this PR to the tmdeveloper007 account.

- Add input validation for userId (must be non-empty string) and type
- Wrap all async database operations in try/catch to prevent unhandled rejections
- Handle both select and insert errors explicitly
- Add security test coverage in security-tests/activity-util.test.cjs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant