Skip to content

Conversation

@marklearst
Copy link
Owner

Add comprehensive JSDoc documentation explaining mutation return value behavior:

  • MutationResult interface: Detailed docs with code examples showing all three patterns (check return value, try/catch, reactive status flags)
  • MutationOptions.throwOnError: Clear explanation of both modes
  • useCreateVariable: Added return value section and improved example
  • useUpdateVariable: Added return value section and improved example
  • useDeleteVariable: Added return value section and improved example
  • useBulkUpdateVariables: Added return value section and improved example

Key documentation points:

  • mutate() returns Promise<TData | undefined>
  • On success: returns TData
  • On error (throwOnError: false): returns undefined, error in state
  • On error (throwOnError: true): throws error

Also fixes:

  • src/utils/retry.ts: Changed /* istanbul ignore next / to / c8 ignore next */ for proper Codecov/Vitest V8 coverage exclusion

Refs: Codex Audit Item #3, #9

Add comprehensive JSDoc documentation explaining mutation return value behavior:

- MutationResult interface: Detailed docs with code examples showing all three patterns
  (check return value, try/catch, reactive status flags)
- MutationOptions.throwOnError: Clear explanation of both modes
- useCreateVariable: Added return value section and improved example
- useUpdateVariable: Added return value section and improved example
- useDeleteVariable: Added return value section and improved example
- useBulkUpdateVariables: Added return value section and improved example

Key documentation points:
- mutate() returns Promise<TData | undefined>
- On success: returns TData
- On error (throwOnError: false): returns undefined, error in state
- On error (throwOnError: true): throws error

Also fixes:
- src/utils/retry.ts: Changed /* istanbul ignore next */ to /* c8 ignore next */
  for proper Codecov/Vitest V8 coverage exclusion

Refs: Codex Audit Item #3, #9
Copilot AI review requested due to automatic review settings December 30, 2025 00:58
@marklearst marklearst merged commit 85fb384 into main Dec 30, 2025
6 checks passed
@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.37%. Comparing base (f24002b) to head (951c858).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #16      +/-   ##
==========================================
+ Coverage   91.28%   91.37%   +0.09%     
==========================================
  Files          36       36              
  Lines         987      986       -1     
  Branches      284      283       -1     
==========================================
  Hits          901      901              
+ Misses         85       84       -1     
  Partials        1        1              
Flag Coverage Δ
unittests 91.37% <100.00%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive JSDoc documentation to explain mutation return value behavior and error handling semantics for mutation hooks. The documentation clarifies how the mutate() function returns Promise<TData | undefined>, with different behavior based on the throwOnError option.

Key changes:

  • Enhanced MutationResult and MutationOptions interfaces with detailed documentation and code examples
  • Added "Return Value" sections to all mutation hooks explaining success/error handling patterns
  • Updated code examples across all hooks to demonstrate async/await usage and result checking
  • Fixed coverage comment syntax from istanbul to c8 for Vitest/V8 compatibility

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/utils/retry.ts Updated coverage exclusion comment from istanbul to c8 for Vitest/V8 coverage tools
src/types/mutations.ts Enhanced MutationOptions.throwOnError and MutationResult with comprehensive documentation including three recommended usage patterns
src/hooks/useCreateVariable.ts Added return value documentation section and improved example with async/await pattern
src/hooks/useUpdateVariable.ts Added return value documentation section and improved example with async/await pattern
src/hooks/useDeleteVariable.ts Added return value documentation section and improved example with async/await pattern
src/hooks/useBulkUpdateVariables.ts Added return value documentation section and improved example with async/await pattern

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +364 to +369
* // Pattern 3: Use status flags (reactive)
* if (isSuccess) {
* console.log('Created:', data);
* }
* if (isError) {
* console.error('Failed:', error);
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

In Pattern 3, the variables isSuccess, isError, data, and error are referenced without context. These are properties of the MutationResult object and should be shown as being destructured from the hook or accessed via dot notation to provide accurate guidance to developers.

Suggested change
* // Pattern 3: Use status flags (reactive)
* if (isSuccess) {
* console.log('Created:', data);
* }
* if (isError) {
* console.error('Failed:', error);
* // Pattern 3: Use status flags (reactive) from the mutation result
* const mutation = useCreateVariable();
*
* if (mutation.isSuccess) {
* console.log('Created:', mutation.data);
* }
* if (mutation.isError) {
* console.error('Failed:', mutation.error);

Copilot uses AI. Check for mistakes.
Comment on lines +345 to +354
* ```ts
* // Pattern 1: Check return value (when throwOnError is false)
* const result = await mutate(payload);
* if (result === undefined) {
* // Check error state
* console.error('Mutation failed:', error);
* } else {
* // Use result
* console.log('Created:', result);
* }
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

In Pattern 1, the variable error is referenced without context. The code example shows console.error('Mutation failed:', error); but error is not in scope within this standalone example - it's a property of the MutationResult object. This should be shown as accessing the error from the mutation result object (e.g., destructured from the hook or accessed via dot notation) to provide accurate guidance to developers.

Copilot uses AI. Check for mistakes.
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