Skip to content

fix: add shutter api env set check #2077

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

Merged
merged 2 commits into from
Aug 11, 2025
Merged

fix: add shutter api env set check #2077

merged 2 commits into from
Aug 11, 2025

Conversation

kemuru
Copy link
Contributor

@kemuru kemuru commented Aug 9, 2025

PR-Codex overview

This PR adds a validation check for the REACT_APP_SHUTTER_API environment variable in the handleCommit function. If the variable is not set or is empty, an error is logged, and an exception is thrown to prevent further execution.

Detailed summary

  • Added a check for REACT_APP_SHUTTER_API in handleCommit.
  • Logs an error if the variable is not set or empty.
  • Throws an error to prevent committing a vote when the variable is missing.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling to prevent voting actions when required configuration is missing, ensuring a smoother and more predictable user experience.

@kemuru kemuru requested a review from a team as a code owner August 9, 2025 20:11
Copy link

netlify bot commented Aug 9, 2025

Deploy Preview for kleros-v2-testnet-devtools ready!

Name Link
🔨 Latest commit 89848ea
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/6897ac208c88d6000850719d
😎 Deploy Preview https://deploy-preview-2077--kleros-v2-testnet-devtools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

coderabbitai bot commented Aug 9, 2025

Walkthrough

A guard clause was introduced at the beginning of the handleCommit callback within the Commit React component to ensure the REACT_APP_SHUTTER_API environment variable is set. If the variable is missing, an error is logged and execution is halted by throwing an exception.

Changes

Cohort / File(s) Change Summary
Commit Callback Env Check
web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx
Added a check in handleCommit to verify REACT_APP_SHUTTER_API is defined before proceeding.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested labels

Type: Bug :bug:, Package: Web

Suggested reviewers

  • tractorss
  • alcercu

Poem

A bunny hopped to check the code,
For missing envs along the road.
Now errors log, and bugs are caught,
So votes commit as they ought.
With every hop, the code grows neat—
A carrot treat for each defeat! 🥕

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8942cd and 89848ea.

📒 Files selected for processing (1)
  • web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: contracts-testing
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/add-shutter-api-check

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Aug 9, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 89848ea
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/6897ac20c7e75600087f3cda
😎 Deploy Preview https://deploy-preview-2077--kleros-v2-neo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

netlify bot commented Aug 9, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 89848ea
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/6897ac206ad27f000841f530
😎 Deploy Preview https://deploy-preview-2077--kleros-v2-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@kemuru kemuru changed the title fix: add shutter api check fix: add shutter api env set check Aug 9, 2025
Copy link

netlify bot commented Aug 9, 2025

Deploy Preview for kleros-v2-university failed. Why did it fail? →

Name Link
🔨 Latest commit 89848ea
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-university/deploys/6897ac20ed73f3000871006b

Copy link
Contributor

@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.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3080c8f and a8942cd.

📒 Files selected for processing (1)
  • web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (10)
📓 Common learnings
Learnt from: jaybuidl
PR: kleros/kleros-v2#1582
File: web-devtools/src/app/(main)/ruler/SelectArbitrable.tsx:88-90
Timestamp: 2024-10-09T10:22:41.474Z
Learning: Next.js recommends using the `useEffect` hook to set `isClient` and using `suppressHydrationWarning` as a workaround for handling hydration inconsistencies, especially when dealing with data like `knownArbitrables` that may differ between server-side and client-side rendering. This approach is acceptable in TypeScript/React applications, such as in `web-devtools/src/app/(main)/ruler/SelectArbitrable.tsx`.
📚 Learning: 2024-10-09T10:22:41.474Z
Learnt from: jaybuidl
PR: kleros/kleros-v2#1582
File: web-devtools/src/app/(main)/ruler/SelectArbitrable.tsx:88-90
Timestamp: 2024-10-09T10:22:41.474Z
Learning: Next.js recommends using the `useEffect` hook to set `isClient` and using `suppressHydrationWarning` as a workaround for handling hydration inconsistencies, especially when dealing with data like `knownArbitrables` that may differ between server-side and client-side rendering. This approach is acceptable in TypeScript/React applications, such as in `web-devtools/src/app/(main)/ruler/SelectArbitrable.tsx`.

Applied to files:

  • web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx
📚 Learning: 2024-11-21T05:38:11.576Z
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1755
File: kleros-app/src/lib/atlas/hooks/useSessionStorage.ts:3-12
Timestamp: 2024-11-21T05:38:11.576Z
Learning: In the `useSessionStorage` hook in `kleros-app/src/lib/atlas/hooks/useSessionStorage.ts`, the error handling in the `catch` block covers cases where `window` is undefined or `sessionStorage` throws an exception, so additional checks are unnecessary.

Applied to files:

  • web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx
📚 Learning: 2024-10-09T10:18:51.089Z
Learnt from: jaybuidl
PR: kleros/kleros-v2#1582
File: web-devtools/src/app/(main)/ruler/RulingModes.tsx:179-199
Timestamp: 2024-10-09T10:18:51.089Z
Learning: In `web-devtools/src/app/(main)/ruler/RulingModes.tsx`, the `handleUpdate` function already handles errors via `wrapWithToast`, so additional error handling is unnecessary.

Applied to files:

  • web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx
📚 Learning: 2024-12-16T17:17:32.359Z
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1794
File: web/src/hooks/useStarredCases.tsx:13-18
Timestamp: 2024-12-16T17:17:32.359Z
Learning: In `useStarredCases.tsx`, when handling the `starredCases` Map from local storage, direct mutation is acceptable to prevent the overhead of copying, provided it doesn't adversely affect React's render cycle.

Applied to files:

  • web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx
📚 Learning: 2024-10-15T16:18:32.543Z
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1687
File: web/src/context/AtlasProvider.tsx:225-244
Timestamp: 2024-10-15T16:18:32.543Z
Learning: In `web/src/context/AtlasProvider.tsx`, the `atlasUri` variable comes from environment variables and does not change, so it does not need to be included in dependency arrays.

Applied to files:

  • web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx
📚 Learning: 2024-12-06T13:04:50.495Z
Learnt from: kemuru
PR: kleros/kleros-v2#1774
File: web/src/components/CasesDisplay/index.tsx:61-61
Timestamp: 2024-12-06T13:04:50.495Z
Learning: In `web/src/components/CasesDisplay/index.tsx`, the variables `numberDisputes` and `numberClosedDisputes` can sometimes be `NaN`, and should default to `0` using logical OR (`||`) to prevent display issues in the `StatsAndFilters` component.

Applied to files:

  • web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx
📚 Learning: 2024-10-29T10:14:52.512Z
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1729
File: web/src/layout/Header/navbar/Menu/Settings/Notifications/FormContactDetails/index.tsx:125-127
Timestamp: 2024-10-29T10:14:52.512Z
Learning: In `web/src/layout/Header/navbar/Menu/Settings/Notifications/FormContactDetails/index.tsx`, when `isEmailUpdateable` is false, `user?.emailUpdateableAt` is always defined. Therefore, using the non-null assertion `!` with `user?.emailUpdateableAt!` is acceptable because TypeScript may not infer its definiteness.

Applied to files:

  • web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx
📚 Learning: 2024-10-29T10:13:04.524Z
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1729
File: web/src/layout/Header/navbar/Menu/Settings/Notifications/FormContactDetails/index.tsx:69-69
Timestamp: 2024-10-29T10:13:04.524Z
Learning: In `web/src/layout/Header/navbar/Menu/Settings/Notifications/FormContactDetails/index.tsx`, when the button is disabled, the associated logic won't be reached, and certain code paths may exist for TypeScript purposes.

Applied to files:

  • web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx
📚 Learning: 2024-11-07T10:48:16.774Z
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1739
File: web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx:22-26
Timestamp: 2024-11-07T10:48:16.774Z
Learning: In the `Coherency` component (`web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx`), `totalResolvedVotes` is always greater than or equal to `totalCoherentVotes`. When both are zero, `0/0` results in `NaN`, which is acceptable in this context.

Applied to files:

  • web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (javascript)
  • GitHub Check: contracts-testing

Comment on lines 88 to 91
if (!import.meta.env.REACT_APP_SHUTTER_API) {
console.error("REACT_APP_SHUTTER_API environment variable is not set");
throw new Error("Cannot commit vote: REACT_APP_SHUTTER_API environment variable is required but not set");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Env var prefix likely incorrect for Vite; guard will always fail. Also avoid throwing in UI handler.

This app uses import.meta.env (Vite). Client-exposed env vars must be prefixed with VITE_. Checking REACT_APP_SHUTTER_API (CRA-style) will be undefined at runtime, causing this path to always throw and break committing. Prefer VITE_SHUTTER_API, optionally falling back to REACT_APP_SHUTTER_API for backward compatibility. Also, throwing here creates an unhandled rejection UX; return early and surface a user-facing message instead.

Apply:

-      if (!import.meta.env.REACT_APP_SHUTTER_API) {
-        console.error("REACT_APP_SHUTTER_API environment variable is not set");
-        throw new Error("Cannot commit vote: REACT_APP_SHUTTER_API environment variable is required but not set");
-      }
+      // Prefer VITE_ (Vite). Fallback to REACT_APP_ only if you still ship CRA envs.
+      const SHUTTER_API =
+        import.meta.env.VITE_SHUTTER_API ?? import.meta.env["REACT_APP_SHUTTER_API"];
+      if (!SHUTTER_API) {
+        console.error("Missing Shutter API URL. Set VITE_SHUTTER_API (preferred) or REACT_APP_SHUTTER_API.");
+        // TODO: replace with a user-facing toast/notification if available
+        return;
+      }

Notes:

  • Use bracket notation for REACT_APP_SHUTTER_API to avoid TS property typing errors.
  • Consider hoisting SHUTTER_API to a module-level const to avoid re-evaluating inside the callback (envs are static at build time).
🤖 Prompt for AI Agents
In web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx around lines 88 to
91, the environment variable check uses the incorrect prefix
REACT_APP_SHUTTER_API which is not exposed by Vite at runtime, causing the guard
to always fail. Change the check to use import.meta.env.VITE_SHUTTER_API,
optionally falling back to import.meta.env["REACT_APP_SHUTTER_API"] using
bracket notation to avoid TS errors. Hoist this environment variable to a
module-level constant to prevent repeated evaluation. Instead of throwing an
error inside the UI handler, return early and display a user-facing error
message to avoid unhandled promise rejections.

💡 Verification agent

🧩 Analysis chain

Surface configuration error earlier and disable the action rather than fail on click.

Prefer determining readiness once (e.g., const isShutterReady = Boolean(SHUTTER_API)) and disabling the commit UI or showing an inline warning, instead of throwing during the click handler. This prevents unhandled rejections and provides clearer UX.

You can verify consistency of env usage and whether OptionsContainer supports a disabled or notice prop:


🏁 Script executed:

#!/bin/bash
# Inspect env usage patterns to ensure VITE_ is standard in the repo.
rg -n "import.meta.env\." -S | sed -E 's/.*import\.meta\.env\.([A-Z0-9_]+).*/\1/' | sort -u

# Look for OptionsContainer props to see if we can disable/notify from parent.
fd -t f OptionsContainer | xargs -I{} sh -c 'echo "==> {}"; sed -n "1,200p" "{}"'

Length of output: 4625


Compute Shutter readiness up-front & disable commit UI instead of throwing

Rather than throwing in the click handler, derive a single const isShutterReady = Boolean(import.meta.env.REACT_APP_SHUTTER_API) at the top of the component. Then:

  • Pass disabled={!isShutterReady || isLoading} (and optionally an inline tooltip or notice when !isShutterReady) to your commit <Button>.
  • Optionally render a short warning message above or below the button when isShutterReady is false.

This surfaces configuration issues immediately, prevents unhandled rejections on click, and gives the user clearer feedback.

• File: web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx
• Replace lines 88–91 with an upfront isShutterReady check and wire it into the button’s disabled/title (or inline notice) props.

🤖 Prompt for AI Agents
In web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx around lines 88 to
91, replace the runtime throw error for missing REACT_APP_SHUTTER_API with a
computed constant isShutterReady at the top of the component. Use this constant
to disable the commit button by passing disabled={!isShutterReady || isLoading}
and optionally add a tooltip or inline warning message near the button when
isShutterReady is false. This change prevents throwing errors on click and
provides immediate user feedback about configuration issues.

Copy link

sonarqubecloud bot commented Aug 9, 2025

@jaybuidl jaybuidl merged commit a130a6a into dev Aug 11, 2025
19 of 25 checks passed
@jaybuidl jaybuidl deleted the fix/add-shutter-api-check branch August 11, 2025 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants