Skip to content

fix: Improve error handling for ecosystem seed script #1590

Open
sujitaw wants to merge 1 commit intomainfrom
fix/add_more_specific_error_message_seed_script
Open

fix: Improve error handling for ecosystem seed script #1590
sujitaw wants to merge 1 commit intomainfrom
fix/add_more_specific_error_message_seed_script

Conversation

@sujitaw
Copy link
Copy Markdown
Contributor

@sujitaw sujitaw commented Mar 26, 2026

What

  • Improve error handling messages to be specific

Summary by CodeRabbit

  • Chores
    • Improved error messaging for environment variable validation during initialization, providing more targeted feedback when configuration is incomplete.

Signed-off-by: sujitaw <[email protected]>
@sujitaw sujitaw requested a review from shitrerohit March 26, 2026 05:56
@sujitaw sujitaw self-assigned this Mar 26, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 26, 2026

📝 Walkthrough

Walkthrough

The createKeycloakUser() function's environment variable validation was refactored to check five required variables individually with specific error messages for each missing variable, replacing the previous combined validation approach.

Changes

Cohort / File(s) Summary
Environment Variable Validation
libs/prisma-service/prisma/seed.ts
Replaced single combined validation with individual checks for KEYCLOAK_DOMAIN, KEYCLOAK_REALM, PLATFORM_ADMIN_KEYCLOAK_ID, PLATFORM_ADMIN_KEYCLOAK_SECRET, and CRYPTO_PRIVATE_KEY, providing targeted error messages per missing variable.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • shitrerohit
  • tipusinghaw

Poem

🐰 Five checks now instead of one,
Each variable gets its validation run,
Clear messages hop through the code,
No more guessing down the troubleshooting road! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: improving error handling in the ecosystem seed script with more specific error messages.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/add_more_specific_error_message_seed_script

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
libs/prisma-service/prisma/seed.ts (1)

683-701: Good improvement for specific error messages; consider extracting to a utility.

The individual validation provides clear, actionable error messages for debugging. However, this pattern is repetitive and inconsistent with the combined check in getKeycloakToken() (line 636).

Consider extracting a reusable utility function to validate required environment variables, which would reduce duplication and ensure consistent error handling across the codebase.

♻️ Proposed utility function
function validateRequiredEnvVars(varNames: string[]): void {
  for (const name of varNames) {
    if (!process.env[name]) {
      throw new Error(`Missing environment variable: ${name}`);
    }
  }
}

Then in createKeycloakUser():

-  if (!KEYCLOAK_DOMAIN) {
-    throw new Error('Missing environment variable: KEYCLOAK_DOMAIN');
-  }
-
-  if (!KEYCLOAK_REALM) {
-    throw new Error('Missing environment variable: KEYCLOAK_REALM');
-  }
-
-  if (!PLATFORM_ADMIN_KEYCLOAK_ID) {
-    throw new Error('Missing environment variable: PLATFORM_ADMIN_KEYCLOAK_ID');
-  }
-
-  if (!PLATFORM_ADMIN_KEYCLOAK_SECRET) {
-    throw new Error('Missing environment variable: PLATFORM_ADMIN_KEYCLOAK_SECRET');
-  }
-
-  if (!CRYPTO_PRIVATE_KEY) {
-    throw new Error('Missing environment variable: CRYPTO_PRIVATE_KEY');
-  }
+  validateRequiredEnvVars([
+    'KEYCLOAK_DOMAIN',
+    'KEYCLOAK_REALM', 
+    'PLATFORM_ADMIN_KEYCLOAK_ID',
+    'PLATFORM_ADMIN_KEYCLOAK_SECRET',
+    'CRYPTO_PRIVATE_KEY'
+  ]);

Based on learnings: "the team prefers to create utilities for validating required environment variables rather than implementing inline validation."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@libs/prisma-service/prisma/seed.ts` around lines 683 - 701, Extract a small
utility function validateRequiredEnvVars(varNames: string[]) that iterates the
list and throws `new Error(\`Missing environment variable: ${name}\`)` for any
missing env var, then replace the inline repetitive checks in
createKeycloakUser() with a single call to validateRequiredEnvVars([...])
including KEYCLOAK_DOMAIN, KEYCLOAK_REALM, PLATFORM_ADMIN_KEYCLOAK_ID,
PLATFORM_ADMIN_KEYCLOAK_SECRET, CRYPTO_PRIVATE_KEY; also update
getKeycloakToken() to reuse the same utility for consistent behavior and ensure
the new function is exported/imported where needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@libs/prisma-service/prisma/seed.ts`:
- Around line 683-701: Extract a small utility function
validateRequiredEnvVars(varNames: string[]) that iterates the list and throws
`new Error(\`Missing environment variable: ${name}\`)` for any missing env var,
then replace the inline repetitive checks in createKeycloakUser() with a single
call to validateRequiredEnvVars([...]) including KEYCLOAK_DOMAIN,
KEYCLOAK_REALM, PLATFORM_ADMIN_KEYCLOAK_ID, PLATFORM_ADMIN_KEYCLOAK_SECRET,
CRYPTO_PRIVATE_KEY; also update getKeycloakToken() to reuse the same utility for
consistent behavior and ensure the new function is exported/imported where
needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 15ee697c-9230-4fc8-91d0-810af2f5c348

📥 Commits

Reviewing files that changed from the base of the PR and between ab28429 and 7c02ce5.

📒 Files selected for processing (1)
  • libs/prisma-service/prisma/seed.ts

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.

2 participants