Skip to content

feat: remove http-assert #18

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 3 commits into from
Mar 13, 2025
Merged

feat: remove http-assert #18

merged 3 commits into from
Mar 13, 2025

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Mar 12, 2025

Summary by CodeRabbit

  • Documentation
    • Revised content by removing an outdated external library reference, ensuring clarity without affecting functionality.
  • Chores
    • Removed unused external dependencies to streamline project configuration.
  • Refactor
    • Streamlined internal error-handling logic, maintaining the same user-facing behavior while simplifying the underlying process.
  • Tests
    • Enhanced test cases for error handling in the ctx.assert function, improving clarity and maintainability.

@fengmk2 fengmk2 requested a review from Copilot March 12, 2025 16:26
Copy link

coderabbitai bot commented Mar 12, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes remove all references to the external http-assert package from the project. The documentation no longer mentions http-assert, and its dependencies have been removed from the package manifest. In the source code, the Context.assert method has been simplified by replacing the former dependency-based logic with a direct check and error creation via the internal createError function. No public API alterations have been made.

Changes

Files Summary of Changes
docs/.../context.md & package.json Removed reference to http-assert from the documentation and deleted http-assert and @types/http-assert from dependencies.
src/context.ts Simplified the assert method by removing the call to http-assert and directly invoking createError to throw errors when the condition is not met.
test/.../assert.test.ts Restructured error handling in tests for ctx.assert, replacing try-catch with assert.throws. Added new test cases for various error scenarios, enhancing clarity and maintainability of the tests.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant Context as Context.assert
    participant Error as createError

    Caller->>Context: call assert(value, status, errorMessage?, errorProps?)
    alt Value is truthy
        Context->>Caller: continue execution
    else Value is falsy
        Context->>Error: call createError(status, errorMessage, errorProps)
        Error-->>Context: error object
        Context-->>Caller: throw error
    end
Loading

Poem

I’m a bunny in the code burrow,
Hopping over changes mellow.
No more old assert tricks to behold,
A fresh error flow now clearly unfolds.
With each leap, new logic takes flight –
Carrots and code, both shining bright!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

test/context/assert.test.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eggache".

(The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eggache@latest --save-dev

The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg/typescript » ./index.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 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 1ecf4e1 and 9470e95.

📒 Files selected for processing (1)
  • test/context/assert.test.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 docstrings to generate docstrings 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 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

@Copilot 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 pull request removes the dependency on http-assert, updating the assertion implementation and the related documentation accordingly.

  • Removed the import and usage of http-assert in src/context.ts, replacing it with a direct error throw using createError.
  • Updated the API docs in docs/api/context.md to eliminate outdated references to http-assert.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/context.ts Replaced http-assert with a custom assert implementation using createError.
docs/api/context.md Removed outdated documentation referencing http-assert.

Copy link

pkg-pr-new bot commented Mar 12, 2025

Open in Stackblitz

npm i https://pkg.pr.new/eggjs/koa/@eggjs/koa@18

commit: 9470e95

Copy link

socket-security bot commented Mar 12, 2025

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: npm/[email protected]

View full report↗︎

Copy link

@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: 1

🧹 Nitpick comments (2)
src/context.ts (2)

83-86: Implementation simplified but watch for undefined parameters

The implementation has been streamlined by removing the dependency on http-assert, which aligns with the PR objective. However, the direct use of non-null assertions (!) on parameters assumes they will be defined when needed.

Consider adding null checks or default values to make the code more robust:

- throw createError(status!, msgOrOptions!, opts!);
+ throw createError(
+   status || 500,
+   typeof msgOrOptions === 'string' || msgOrOptions ? msgOrOptions : 'Assertion failed',
+   opts
+ );

71-79: JSDoc parameters don't match signature and implementation

The JSDoc parameter documentation doesn't accurately reflect the method signature and implementation. The @param {String} opts comment is incorrect as the opts parameter is actually Record<string, any>.

Update the JSDoc to match the method signature:

 /**
  * Similar to .throw(), adds assertion.
  *
  *    this.assert(this.user, 401, 'Please login!');
  *
  * @param {Mixed} value
  * @param {Number} status
- * @param {String} opts
+ * @param {String|Object} msgOrOptions - Error message or options
+ * @param {Object} [opts] - Error options
  */
🧰 Tools
🪛 GitHub Actions: Node.js CI

[warning] 79-79: http-errors deprecated non-error status code; use only 4xx or 5xx status codes

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8027bad and 80c7c3a.

📒 Files selected for processing (3)
  • docs/api/context.md (0 hunks)
  • package.json (0 hunks)
  • src/context.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • docs/api/context.md
  • package.json
🧰 Additional context used
🪛 GitHub Actions: Node.js CI
src/context.ts

[warning] 79-79: http-errors deprecated non-error status code; use only 4xx or 5xx status codes

Copy link

codecov bot commented Mar 13, 2025

Codecov Report

Attention: Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.

Project coverage is 98.35%. Comparing base (cd6b487) to head (9470e95).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/context.ts 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #18      +/-   ##
==========================================
- Coverage   98.45%   98.35%   -0.10%     
==========================================
  Files           6        6              
  Lines        1939     1946       +7     
  Branches      368      373       +5     
==========================================
+ Hits         1909     1914       +5     
- Misses         30       32       +2     

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

@fengmk2 fengmk2 merged commit ce79a68 into master Mar 13, 2025
21 of 24 checks passed
@fengmk2 fengmk2 deleted the remove-http-assert branch March 13, 2025 15:52
fengmk2 pushed a commit that referenced this pull request Mar 13, 2025
[skip ci]

## [2.21.0](v2.20.7...v2.21.0) (2025-03-13)

### Features

* remove http-assert ([#18](#18)) ([ce79a68](ce79a68))
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