Skip to content

Conversation

@aashu2006
Copy link

@aashu2006 aashu2006 commented Jan 9, 2026

Proposed Changes

Improves the error message shown when importing a questionnaire fails.
The updated message is clearer and more user-friendly.

No existing behavior is changed.

Requesting review from @ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs/tests (not required for text-only change)
  • Update documentation (not applicable)
  • Ensure that UI text is placed in i18n files
  • Screenshots or demo (not applicable for text change)
  • Request peer reviews
  • QA on mobile devices (not required)
  • QA on desktop devices (not required)
  • Add or update Playwright tests (not required)

@aashu2006 aashu2006 requested review from a team January 9, 2026 14:14
@github-actions
Copy link

github-actions bot commented Jan 9, 2026

⚠️ Merge Checklist Incomplete

Thank you for your contribution! To help us review your PR efficiently, please complete the merge checklist in your PR description.

Your PR will be reviewed once you have marked the appropriate checklist items.

To update the checklist:

  • Change - [ ] to - [x] for completed items
  • Only check items that are relevant to your PR
  • Leave items unchecked if they don't apply

The checklist helps ensure code quality, testing coverage, and documentation are properly addressed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 9, 2026

Walkthrough

Updated error message in the importQuestionnaire mutation within QuestionnaireEditor component. Changed error text from "Failed to fetch questionnaire" to "Unable to fetch the questionnaire" on non-ok responses. No behavioral modifications.

Changes

Cohort / File(s) Summary
Error Message Updates
src/components/Questionnaire/QuestionnaireEditor.tsx
Updated error message text in importQuestionnaire mutation from "Failed to fetch questionnaire" to "Unable to fetch the questionnaire" for non-ok HTTP responses
🚥 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
Title check ✅ Passed The title accurately reflects the main change: improving the error message when questionnaire fetch fails, which is the primary objective of the pull request.
Description check ✅ Passed The PR description addresses the main change (improved error message) and properly marks inapplicable checklist items as not required for this text-only change.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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

🤖 Fix all issues with AI agents
In @src/components/Questionnaire/QuestionnaireEditor.tsx:
- Line 414: The thrown Error in the response.ok check uses a hardcoded English
string ("Unable to fetch the questionnaire") in QuestionnaireEditor.tsx; replace
it with an i18n string by calling the existing translation function (e.g.,
useTranslation().t or i18n.t) and throw new
Error(t("unable_to_fetch_questionnaire")) (create that key if missing) so
internal logs and error tracking use localized messages; ensure the module
imports/uses useTranslation (or i18n) consistently with other messages (e.g.,
the onError handler) and update any tests or snapshots that assert the exact
error text.
- Around line 411-416: The fetch error thrown in the mutationFn used by
useMutation for importQuestionnaire lacks HTTP status details; update the
mutationFn (the async (url: string) => { ... }) to include response.status (and
optionally response.statusText) in the thrown Error when !response.ok so the
error message contains the HTTP status code and context to aid debugging.
📜 Review details

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c27358b and 2afd423.

📒 Files selected for processing (1)
  • src/components/Questionnaire/QuestionnaireEditor.tsx
🧰 Additional context used
📓 Path-based instructions (12)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursorrules)

**/*.{ts,tsx}: Write concise, technical TypeScript code with accurate examples
Use TypeScript for all code; prefer interfaces over types
Avoid enums; use maps instead
Use TanStack Query for data fetching from the API along with query and mutate utilities for the queryFn and mutationFn
Use raviger for routing

**/*.{ts,tsx}: Use TypeScript with strict mode and ES2022 target
Use interface for defining object types in TypeScript
Avoid explicit any type in TypeScript
Use proper nullability annotations in TypeScript types
Use dedicated error handlers and TypeScript strict null checks

**/*.{ts,tsx}: Use TypeScript for all new code
Prefer interfaces over types for object definitions in TypeScript
Avoid using any type; use proper type definitions in TypeScript
Use type inference where possible in TypeScript
Use TanStack Query for API data management
Prefer React Context for global state management

**/*.{ts,tsx}: Use TanStack Query with the query and mutate utilities from @/Utils/request/
Use appropriate query keys following the resource pattern for TanStack Query
Leverage TanStack Query built-in features for pagination and debouncing
Implement proper error handling using the global error handler for TanStack Query operations
Use useQuery hook with queryKey and queryFn parameters, where queryFn wraps the API route with the query() utility
Use useMutation hook with mutationFn parameter wrapping API routes with the mutate() utility, and implement onSuccess callbacks to invalidate related queries
Support path parameters in TanStack Query using the pathParams option in query/mutate utilities
Support query parameters in TanStack Query using the queryParams option in query/mutate utilities
Use the silent: true option to suppress global error notifications when custom error handling is needed

**/*.{ts,tsx}: Use TypeScript with strict mode and ES2022 target
Use interface for defining object types
Avoid explicit any types and maint...

Files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursorrules)

**/*.{ts,tsx,js,jsx}: Use functional and declarative programming patterns; avoid classes
Prefer iteration and modularization over code duplication
Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError)
Use the "function" keyword for pure functions
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements

**/*.{ts,tsx,js,jsx}: Use path aliases for imports from src (@/*)
Use double quotes for strings
Semicolons are required at end of statements
Order imports as: 3rd-party → library → CAREUI → UI → components → hooks → utils → relative
Use PascalCase for component and class names
Use camelCase for variable and function names

**/*.{ts,tsx,js,jsx}: Use path aliases @/* for imports from src directory
Use double quotes for strings
Require semicolons at end of statements
Order imports: 3rd-party → library → CAREUI → UI → components → hooks → utils → relative
Use PascalCase for component and class names
Use camelCase for variable and function names

Files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
**/*.{tsx,jsx}

📄 CodeRabbit inference engine (.cursorrules)

Use declarative JSX

Files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

src/**/*.{ts,tsx}: Use strict TypeScript configuration for medical data safety in all TypeScript source files
All literal strings must use i18next for multi-language support in healthcare interfaces
Use comprehensive error boundaries and user-friendly error messages for medical workflow debugging without exposing PHI
Follow ESLint configured rules for React hooks, accessibility, and code quality
Use @tanstack/react-query for server state management in API client code
Localize date and time formats for medical timestamps using locale-aware formatting functions
Use date-fns for date handling and manipulation with locale awareness for medical timestamps

Files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
src/components/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

src/components/**/*.{ts,tsx}: Implement WCAG 2.1 AA accessibility compliance in medical applications with screen reader compatibility and keyboard navigation
Include medical use cases, accessibility notes, and WCAG compliance documentation in component documentation
Follow established React component patterns and folder structure organized by feature and domain

src/components/**/*.{ts,tsx}: Use path aliases: @/components/, @/types/, @/lib/, @/pages/ for imports
Follow import order: External packages → @/components/ui/@/components/@/CAREUI/@/types/@/lib/ → relative imports
Use named exports from lucide-react for icons (e.g., import { SettingsIcon } from "lucide-react")
Import useTranslation from react-i18next for internationalization
Use React 19.1.1 hooks pattern - Functional components only
Always define TypeScript Props interfaces (e.g., PatientInfoCardProps) for component props
Use handle prefix for event handlers (e.g., handleSubmit, handleTagsUpdate, handlePatientSelect)
Use shadcn/ui components as primary UI system (Button, Card, Badge, etc.) from @/components/ui/
Use healthcare-specific CAREUI custom components (Calendar, WeekdayCheckbox, Zoom) from @/CAREUI/
Use buttonVariants from @/components/ui/button with CVA patterns for button styling
Follow <Card><CardHeader> pattern for consistent card layouts
Use PatientRead type from @/types/emr/patient/patient for patient data handling
Implement TagAssignmentSheet with TagEntityType for patient/facility tags
Use PatientHoverCard for patient info overlays
Use Badge components to display patient status, facility capacity, medication dosage with color variants
Use cva() from class variance authority for variant-based component styling
Use cn() from @/lib/utils for conditional class composition
Follow Tailwind CSS 4.1.3 color system: primary-700, gray-900, red-500 pattern with dark mode variants
Use Tailwind shadow system: shadow-sm, shadow-xs for el...

Files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
src/**/*.{ts,tsx,css}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use Prettier for consistent code formatting across the healthcare application

Files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
src/**/*.{tsx,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

src/**/*.{tsx,ts}: Use React 19.1.1 features and patterns following React 19 Documentation for healthcare application development
Use shadcn/ui as primary component system and CAREUI for healthcare-specific components
Use framer-motion for animations in healthcare UI interfaces

Files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
src/**/*.{tsx,css}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use Tailwind CSS 4.1.3 utility classes with custom healthcare-specific design system for styling

Files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
**/*

📄 CodeRabbit inference engine (CLAUDE.md)

Use 2-space indentation

Files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
**/*.tsx

📄 CodeRabbit inference engine (.cursor/rules/02-coding-standards.mdc)

**/*.tsx: Use functional components with proper type definitions in React
One component per file is preferred
Prefer default exports for React components
Follow the component naming pattern: ComponentName.tsx for React components
Use Tailwind CSS for styling
Use Shadcn UI components when available
Use local state for component-specific data
Use PascalCase for component file names (e.g., AuthWizard.tsx)

Files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
**/*.{tsx,ts}

📄 CodeRabbit inference engine (.cursor/rules/04-ui-components.mdc)

**/*.{tsx,ts}: Use Shadcn UI components as the primary component library
Follow the component documentation for proper usage
Customize components using Tailwind CSS
Use navigate and useRedirect from raviger for navigation and redirects
Use Tailwind's responsive classes and follow mobile-first approach
Implement proper ARIA attributes for accessibility
Ensure keyboard navigation works in components
Define component props using TypeScript interfaces
Use translation keys from src/Locale/ for internationalization
Support RTL languages in components
Use proper date/time formatting for multiple language support

Files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
**/*.{ts,tsx,js,jsx,json,css,scss,html}

📄 CodeRabbit inference engine (AGENTS.md)

Use 2-space indentation

Files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
🧠 Learnings (9)
📓 Common learnings
Learnt from: CR
Repo: ohcnetwork/care_fe PR: 0
File: .github/instructions/pages.instructions.md:0-0
Timestamp: 2025-11-25T13:52:19.758Z
Learning: Provide meaningful error messages to users in page components
Learnt from: CR
Repo: ohcnetwork/care_fe PR: 0
File: .github/instructions/hooks.instructions.md:0-0
Timestamp: 2025-11-25T13:51:32.224Z
Learning: Applies to src/hooks/**/*.{ts,tsx} : Provide meaningful error messages for clinical workflows in custom hooks
📚 Learning: 2025-11-25T13:51:32.224Z
Learnt from: CR
Repo: ohcnetwork/care_fe PR: 0
File: .github/instructions/hooks.instructions.md:0-0
Timestamp: 2025-11-25T13:51:32.224Z
Learning: Applies to src/hooks/**/*.{ts,tsx} : Provide meaningful error messages for clinical workflows in custom hooks

Applied to files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
📚 Learning: 2025-11-25T13:50:10.786Z
Learnt from: CR
Repo: ohcnetwork/care_fe PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-25T13:50:10.786Z
Learning: Applies to src/**/*.{ts,tsx} : Use comprehensive error boundaries and user-friendly error messages for medical workflow debugging without exposing PHI

Applied to files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
📚 Learning: 2025-11-25T13:50:46.407Z
Learnt from: CR
Repo: ohcnetwork/care_fe PR: 0
File: .github/instructions/careui.instructions.md:0-0
Timestamp: 2025-11-25T13:50:46.407Z
Learning: Applies to src/CAREUI/**/*.{ts,tsx} : Implement robust error handling with user-friendly medical context in CAREUI components

Applied to files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
📚 Learning: 2025-11-25T13:54:24.075Z
Learnt from: CR
Repo: ohcnetwork/care_fe PR: 0
File: .cursor/rules/03-data-fetching.mdc:0-0
Timestamp: 2025-11-25T13:54:24.075Z
Learning: Applies to **/*.{ts,tsx} : Use `useMutation` hook with `mutationFn` parameter wrapping API routes with the `mutate()` utility, and implement `onSuccess` callbacks to invalidate related queries

Applied to files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
📚 Learning: 2025-03-19T10:14:20.559Z
Learnt from: shivankacker
Repo: ohcnetwork/care_fe PR: 11403
File: src/components/Questionnaire/ValueSetSelect.tsx:278-308
Timestamp: 2025-03-19T10:14:20.559Z
Learning: TanStack Query v5 (previously known as React Query) uses `isPending` instead of `isLoading` for mutation states in the useMutation hook. The usage of `isPending` in the codebase is correct and follows the current API.

Applied to files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
📚 Learning: 2025-01-03T16:26:08.045Z
Learnt from: rithviknishad
Repo: ohcnetwork/care_fe PR: 9708
File: src/components/Users/UserResetPassword.tsx:72-89
Timestamp: 2025-01-03T16:26:08.045Z
Learning: When using react-query’s mutate, avoid chaining the calls as "() => mutate(...)(...)" and just call "mutate(...)" directly, relying on its built-in error handling and the global notification dispatcher.

Applied to files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
📚 Learning: 2025-12-17T19:47:58.152Z
Learnt from: AdityaJ2305
Repo: ohcnetwork/care_fe PR: 14821
File: src/components/Location/LocationNavigation.tsx:161-163
Timestamp: 2025-12-17T19:47:58.152Z
Learning: To ensure the remove-unused-i18n.js cleanup script detects i18n keys, avoid wrapping keys inside a ternary expression passed directly to t(). Instead, call t() separately in each branch of a conditional, e.g. condition ? t("key1") : t("key2"), or compute the key in a variable before passing to t(). For LocationNavigation.tsx (and similar TSX files in the repo), prefer explicit separate i18n calls per branch or a shared precomputed key to guarantee all keys are statically detectable by the script.

Applied to files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx
📚 Learning: 2025-12-22T10:16:36.690Z
Learnt from: Jacobjeevan
Repo: ohcnetwork/care_fe PR: 14804
File: src/pages/Facility/services/pharmacy/DispensesView.tsx:117-135
Timestamp: 2025-12-22T10:16:36.690Z
Learning: In the care_fe repository, prefer the native HTML title attribute for simple tooltips over using shadcn/ui Tooltip components. Use Tooltip components only when the tooltip requires richer content, interactivity, or accessibility enhancements that cannot be achieved with a plain title. For simple cases, add a title attribute to the element (e.g., <span title="...">). If a Tooltip is used, ensure it is accessible and necessary, and avoid duplicating content available in the title attribute.

Applied to files:

  • src/components/Questionnaire/QuestionnaireEditor.tsx

Comment on lines 411 to 416
const { mutate: importQuestionnaire, isPending: isImporting } = useMutation({
mutationFn: async (url: string) => {
const response = await fetch(url);
if (!response.ok) throw new Error("Failed to fetch questionnaire");
if (!response.ok) throw new Error("Unable to fetch the questionnaire");
return response.json();
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider including HTTP status code for better debugging.

The error message could include the HTTP status code to provide more context when troubleshooting failed imports. This would help developers identify whether it's a 404 (not found), 403 (forbidden), 500 (server error), etc.

♻️ Proposed enhancement
  const { mutate: importQuestionnaire, isPending: isImporting } = useMutation({
    mutationFn: async (url: string) => {
      const response = await fetch(url);
-     if (!response.ok) throw new Error("Unable to fetch the questionnaire");
+     if (!response.ok) {
+       throw new Error(
+         `Unable to fetch the questionnaire (HTTP ${response.status}: ${response.statusText})`
+       );
+     }
      return response.json();
    },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const { mutate: importQuestionnaire, isPending: isImporting } = useMutation({
mutationFn: async (url: string) => {
const response = await fetch(url);
if (!response.ok) throw new Error("Failed to fetch questionnaire");
if (!response.ok) throw new Error("Unable to fetch the questionnaire");
return response.json();
},
const { mutate: importQuestionnaire, isPending: isImporting } = useMutation({
mutationFn: async (url: string) => {
const response = await fetch(url);
if (!response.ok) {
throw new Error(
`Unable to fetch the questionnaire (HTTP ${response.status}: ${response.statusText})`
);
}
return response.json();
},
🤖 Prompt for AI Agents
In @src/components/Questionnaire/QuestionnaireEditor.tsx around lines 411 - 416,
The fetch error thrown in the mutationFn used by useMutation for
importQuestionnaire lacks HTTP status details; update the mutationFn (the async
(url: string) => { ... }) to include response.status (and optionally
response.statusText) in the thrown Error when !response.ok so the error message
contains the HTTP status code and context to aid debugging.

mutationFn: async (url: string) => {
const response = await fetch(url);
if (!response.ok) throw new Error("Failed to fetch questionnaire");
if (!response.ok) throw new Error("Unable to fetch the questionnaire");
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Note: Internal error message is hardcoded.

While the user-facing error message is properly internationalized through the onError handler (line 422), the error message thrown here is a hardcoded English string. This is a minor concern since users see the translated message t("failed_to_import_questionnaire"), but the internal error message could still appear in browser console logs or error tracking systems.

The current approach is functional, but consider that the coding guidelines state "All literal strings must use i18next for multi-language support in healthcare interfaces."

Based on coding guidelines requiring i18next for all literal strings in healthcare interfaces.

🤖 Prompt for AI Agents
In @src/components/Questionnaire/QuestionnaireEditor.tsx at line 414, The thrown
Error in the response.ok check uses a hardcoded English string ("Unable to fetch
the questionnaire") in QuestionnaireEditor.tsx; replace it with an i18n string
by calling the existing translation function (e.g., useTranslation().t or
i18n.t) and throw new Error(t("unable_to_fetch_questionnaire")) (create that key
if missing) so internal logs and error tracking use localized messages; ensure
the module imports/uses useTranslation (or i18n) consistently with other
messages (e.g., the onError handler) and update any tests or snapshots that
assert the exact error text.

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.

1 participant