Skip to content

move nextjs & add CI configs#9

Merged
w01fgang merged 2 commits intomainfrom
feat/move-nextjs
Jun 22, 2025
Merged

move nextjs & add CI configs#9
w01fgang merged 2 commits intomainfrom
feat/move-nextjs

Conversation

@w01fgang
Copy link
Copy Markdown
Contributor

@w01fgang w01fgang commented Jun 22, 2025

  • Add GitHub Actions workflows for CI and npm publishing
  • ➖ remove vite
  • ♻️ move to nextjs and refactor

Summary by CodeRabbit

  • Documentation
    • Updated usage examples and API documentation to reflect removal of the .rethrow() method and introduction of the .value() method for result retrieval and error handling.
    • Clarified error handling patterns, emphasizing letting errors bubble up or using default values.
  • New Features
    • Introduced a .value() method to obtain results or default values.
    • Made instances thenable, allowing direct use with await.
  • Bug Fixes
    • Improved error reporting and Sentry integration, ensuring errors are reported only as configured.
  • Chores
    • Updated package configuration, including entry points and peer dependencies.
    • Enhanced and expanded test coverage for error handling and reporting scenarios.
    • Changed TypeScript module system to ES2022.
    • Simplified CI workflow and improved npm publish process.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 22, 2025

Walkthrough

The updates refactor the Try helper for Next.js, shifting its API to remove explicit error rethrowing and introduce a .value() method for retrieving results or defaults. The Sentry integration is now dynamically imported, and internal state and result caching are added. Documentation, tests, and package configuration are updated accordingly.

Changes

File(s) Change Summary
README.md Updated usage, API, and examples to remove .rethrow(), introduce .value(), and clarify error handling.
package.json Updated version, entry points, exports, test scripts, and Sentry peer dependency configuration.
src/tests/Try.test.ts Expanded and refined tests for new .value() method, error handling, Sentry integration, and removed .rethrow() tests.
src/index.ts Deleted file; removed re-exports from ./Try.
src/nextjs/index.ts Refactored Try class: dynamic Sentry import, internal state/result caching, new .value() method, removed .rethrow(), and made thenable.
tsconfig.json Changed module system from "CommonJS" to "ES2022".
.github/workflows/ci.yml Simplified CI workflow: fixed Node version to 20.x, removed matrix, updated test commands, removed build step.
.github/workflows/publish.yml Changed install to npm ci, added test step before build, updated formatting and commands.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TryHelper
    participant Sentry (dynamic)

    User->>TryHelper: new Try(fn)
    User->>TryHelper: .default(value)
    User->>TryHelper: .report() / .breadcrumbs() / .tag()
    User->>TryHelper: .value() or .unwrap()

    alt No error in fn
        TryHelper-->>User: result of fn
    else Error occurs
        alt .report() configured
            TryHelper->>Sentry (dynamic): captureException(error, options)
        end
        alt .default() set
            TryHelper-->>User: default value
        else
            TryHelper-->>User: undefined (via .value()) or throw (via .unwrap())
        end
    end
Loading

Poem

In the warren of code, a new path we tread,
Where errors may bubble, not thrown overhead.
With .value() we fetch what the function may yield,
And Sentry reports errors the moment they're revealed.
No more rethrowing, just hop and retrieve—
This rabbit loves changes that help us achieve! 🐇✨


🪧 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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 sequence diagram to generate a sequence diagram of the changes in 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.

@w01fgang w01fgang changed the title feat/move nextjs move nextjs & add CI configs Jun 22, 2025
Signed-off-by: w01fgang <sumin@unix-center.ru>
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.

Actionable comments posted: 4

🧹 Nitpick comments (3)
src/nextjs/index.ts (3)

130-152: Well-designed method with type safety concerns.

The value() method provides a good non-throwing alternative to unwrap(). The logic correctly separates breadcrumb recording from error reporting.

However, the type casting on line 151 could be improved:

-return (this.config.defaultValue ?? undefined) as any;
+return (this.config.defaultValue as Awaited<T>) ?? undefined;

Or better yet, make the return type more explicit by using a generic constraint in the default() method to ensure type safety.


221-222: Consider a more robust approach for Error cause.

While the @ts-ignore works, consider a more type-safe approach:

-    // @ts-ignore cause is missing in the definition
-    return new Error(this.config.message, { cause: error });
+    const wrappedError = new Error(this.config.message);
+    (wrappedError as any).cause = error;
+    return wrappedError;

Or update your TypeScript configuration to use a more recent version that includes the cause property in the Error constructor definition.


225-235: Thenable implementation may cause confusion.

Making the Try class thenable is interesting, but delegating to .value() instead of .unwrap() might be unexpected for developers who await the instance.

Consider either:

  1. Documenting this behavior clearly since await try will never throw (returns undefined on error)
  2. Or providing a choice in the thenable behavior:
+/**
+ * Make the Try instance thenable. When awaited, this behaves like calling .value()
+ * (returns undefined on error) rather than .unwrap() (throws on error).
+ */

This behavior should be clearly documented since it's non-obvious that awaiting a Try instance won't throw errors.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3692d11 and 5d0d326.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • README.md (5 hunks)
  • package.json (2 hunks)
  • src/__tests__/Try.test.ts (5 hunks)
  • src/index.ts (0 hunks)
  • src/nextjs/index.ts (8 hunks)
  • tsconfig.json (1 hunks)
💤 Files with no reviewable changes (1)
  • src/index.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • tsconfig.json
  • package.json
  • README.md
  • src/tests/Try.test.ts
🔇 Additional comments (2)
src/nextjs/index.ts (2)

104-120: Good error handling logic with behavioral changes.

The conditional error reporting and custom error throwing logic is well-implemented. However, this represents a significant behavioral change from the previous version.

The logic correctly:

  • Only reports to Sentry when explicitly configured with a message
  • Throws custom errors when a message is provided
  • Rethrows original errors otherwise

Ensure that existing consumers are aware of these behavioral changes, particularly the conditional error reporting.


177-180: Good defensive programming with async error reporting.

Making reportError async and using optional chaining for Sentry calls is excellent defensive programming that handles the dynamic import scenario properly.

Comment thread src/nextjs/index.ts
Comment thread src/nextjs/index.ts
Comment thread src/nextjs/index.ts
Comment thread src/nextjs/index.ts
- Simplify CI workflow by removing matrix strategy for Node.js versions, now fixed to 20.x
- Change npm install to npm ci for consistency in both CI and publish workflows
- Update test command in CI workflow to run 'npm run test' instead of 'npm run test:run'

Signed-off-by: w01fgang <sumin@unix-center.ru>
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.

Actionable comments posted: 0

🧹 Nitpick comments (3)
.github/workflows/publish.yml (2)

12-13: Add npm authentication configuration.
Include always-auth: true in the actions/setup-node step to ensure that the NODE_AUTH_TOKEN secret is correctly applied when publishing.

Proposed diff:

-      - uses: actions/setup-node@v3
-        with:
-          node-version: "20.x"
-          registry-url: "https://registry.npmjs.org"
+      - uses: actions/setup-node@v3
+        with:
+          node-version: "20.x"
+          registry-url: "https://registry.npmjs.org"
+          always-auth: true

14-17: Add step names for clarity.
Consider adding name: fields for the npm ci, npm run test, and npm run build steps so the Actions UI shows descriptive labels.

.github/workflows/ci.yml (1)

15-15: Add a descriptive name for the Node.js setup step.
Consider adding a name: "Setup Node.js" above uses: actions/setup-node@v3 to improve readability in the Actions run logs.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5d0d326 and 7537689.

📒 Files selected for processing (2)
  • .github/workflows/ci.yml (1 hunks)
  • .github/workflows/publish.yml (1 hunks)
🔇 Additional comments (5)
.github/workflows/publish.yml (2)

14-15: Use npm ci and run tests before publishing.
Switching to npm ci guarantees a clean, reproducible install, and the explicit npm run test step will prevent publishing on test failures.


19-19: Verify NPM_TOKEN secret is set.
Ensure that secrets.NPM_TOKEN is configured in the repository settings with publish permissions.

.github/workflows/ci.yml (3)

5-7: Restrict CI triggers to the main branch.
Limiting both push and pull_request workflows to branches: [main] ensures that CI runs only for changes targeting your primary release branch.


17-19: Lock Node.js version and enable npm caching.
Pinning node-version: "20.x", specifying registry-url, and using cache: "npm" provides consistent environments and faster dependency installs.


28-28: Run tests via npm run test.
Updating the test command to npm run test aligns with the revised package.json scripts and ensures a single-run test suite.

@w01fgang w01fgang merged commit 315de90 into main Jun 22, 2025
3 checks passed
@w01fgang w01fgang deleted the feat/move-nextjs branch June 22, 2025 12:58
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