Skip to content

fix: findUp should never throw#416

Merged
JounQin merged 2 commits intomasterfrom
fix/find-up
Jun 2, 2025
Merged

fix: findUp should never throw#416
JounQin merged 2 commits intomasterfrom
fix/find-up

Conversation

@JounQin
Copy link
Member

@JounQin JounQin commented Jun 2, 2025

Important

findUp in helpers.ts now handles errors gracefully by removing throw options and wrapping fs.statSync in a try-catch.

  • Behavior:
    • findUp function in helpers.ts no longer throws errors for invalid stop paths or when stop is not found.
    • Removed throwOnStopNotFound and throwOnInvalidStop options from FindUpOptions.
  • Error Handling:
    • Wrapped fs.statSync call in tryFileStats with a try-catch block to prevent exceptions from propagating.

This description was created by Ellipsis for 662edc3. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling in file search functionality to prevent unexpected exceptions.
  • Refactor
    • Simplified search logic for improved reliability and maintainability.

@JounQin JounQin requested a review from Copilot June 2, 2025 13:20
@JounQin JounQin self-assigned this Jun 2, 2025
@JounQin JounQin added the bug Something isn't working label Jun 2, 2025
@changeset-bot
Copy link

changeset-bot bot commented Jun 2, 2025

🦋 Changeset detected

Latest commit: ef22a4a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@pkgr/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Jun 2, 2025

Walkthrough

The changes remove stop path validation and related error handling from the findUp function and its options, simplifying its logic. The tryFileStats helper is updated to silently return undefined on errors. A new changeset documents the patch update for the @pkgr/core package.

Changes

File(s) Change Summary
packages/core/src/helpers.ts Removed stop path validation and error throwing from findUp; updated tryFileStats for silent failure; removed related options from FindUpOptions.
.changeset/giant-trainers-swim.md Added changeset documenting the patch update for @pkgr/core regarding findUp error handling.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant findUp
    participant tryFileStats

    Caller->>findUp: Call with entry, stop, and options
    loop Upward Search
        findUp->>tryFileStats: Check if file exists at current path
        tryFileStats-->>findUp: Return stats or undefined (no error thrown)
        alt File found
            findUp-->>Caller: Return found file path
        end
        alt Reached stop or root
            findUp-->>Caller: Return undefined
        end
    end
Loading

Possibly related PRs

Suggested labels

refactor

Poem

In the warren of code, a rabbit did leap,
Removing old warnings, letting errors sleep.
No more will findUp shout or complain,
It searches in silence, through sunshine or rain.
With gentle new logic, the patch hops ahead—
Bugs now are quiet, and nothing to dread!
🐇✨

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.

packages/core/src/helpers.ts

Oops! Something went wrong! :(

ESLint: 9.28.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.js
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:799:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:723:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:706:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:307:38)
at #link (node:internal/modules/esm/module_job:170:49)

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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 docstrings to generate docstrings for this 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 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.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 2, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@codecov
Copy link

codecov bot commented Jun 2, 2025

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 9.72%. Comparing base (8d23d71) to head (ef22a4a).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
packages/core/src/helpers.ts 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           master    #416      +/-   ##
=========================================
+ Coverage    9.17%   9.72%   +0.55%     
=========================================
  Files          12      12              
  Lines         458     432      -26     
  Branches      205     185      -20     
=========================================
  Hits           42      42              
+ Misses        416     390      -26     

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

@github-actions
Copy link
Contributor

github-actions bot commented Jun 2, 2025

📊 Package size report   No changes

File Before After
Total (Includes all files) 3.1 MB 3.1 MB
Tarball size 1.1 MB 1.1 MB
Unchanged files
File Size
.changeset/config.json 309 B
.changeset/README.md 510 B
.codesandbox/ci.json 76 B
.editorconfig 145 B
.gitattributes 35 B
.github/workflows/autofix.yml 921 B
.github/workflows/ci.yml 1.7 kB
.github/workflows/pkg-pr-new.yml 645 B
.github/workflows/pkg-size.yml 727 B
.github/workflows/release.yml 1.5 kB
.github/workflows/vercel.yml 1.0 kB
.markuplintrc 43 B
.nano-staged.js 48 B
.nvmrc 6 B
.prettierignore 6 B
.remarkrc 42 B
.renovaterc 49 B
.simple-git-hooks.js 49 B
.stylelintignore 99 B
.stylelintrc 42 B
.yarn/plugins/plugin-prepare-lifecycle.cjs 202 B
.yarn/releases/yarn-4.9.1.cjs 3.0 MB
.yarnrc.yml 397 B
CHANGELOG.md 486 B
docs/App.tsx 1.2 kB
docs/global.css 321 B
docs/index.tsx 299 B
eslint.config.js 302 B
index.html 402 B
LICENSE 1.1 kB
package.json 3.0 kB
packages/browser/CHANGELOG.md 1.7 kB
packages/browser/index.d.cts 60 B
packages/browser/index.ts 4.7 kB
packages/browser/openChrome.applescript 2.5 kB
packages/browser/package.json 998 B
packages/browser/tsconfig.json 139 B
packages/core/CHANGELOG.md 3.0 kB
packages/core/index.d.cts 54 B
packages/core/package.json 945 B
packages/core/src/constants.ts 538 B
packages/core/src/helpers.ts 3.8 kB
packages/core/src/index.ts 60 B
packages/core/tsconfig.json 154 B
packages/es-modules/CHANGELOG.md 5.2 kB
packages/es-modules/index.d.cts 64 B
packages/es-modules/index.ts 1.4 kB
packages/es-modules/package.json 1.0 kB
packages/es-modules/README.md 3.7 kB
packages/es-modules/test/test.spec.ts 936 B
packages/es-modules/tsconfig.json 139 B
packages/imagemin/CHANGELOG.md 9.2 kB
packages/imagemin/index.d.cts 57 B
packages/imagemin/package.json 1.3 kB
packages/imagemin/src/cli.ts 508 B
packages/imagemin/src/index.ts 1.2 kB
packages/imagemin/tsconfig.json 154 B
packages/rollup/CHANGELOG.md 22.4 kB
packages/rollup/package.json 1.5 kB
packages/rollup/shim.d.ts 647 B
packages/rollup/src/cli.ts 4.0 kB
packages/rollup/src/config.ts 11.9 kB
packages/rollup/tsconfig.json 132 B
packages/umd-globals/CHANGELOG.md 6.2 kB
packages/umd-globals/index.d.cts 66 B
packages/umd-globals/index.ts 1.8 kB
packages/umd-globals/package.json 919 B
packages/umd-globals/README.md 3.4 kB
packages/umd-globals/test/test.spec.ts 1.9 kB
packages/umd-globals/tsconfig.json 139 B
packages/utils/CHANGELOG.md 12.7 kB
packages/utils/index.d.cts 51 B
packages/utils/package.json 961 B
packages/utils/src/constants.ts 497 B
packages/utils/src/helpers.ts 2.8 kB
packages/utils/src/index.ts 117 B
packages/utils/src/monorepo.ts 691 B
packages/utils/tsconfig.json 154 B
README.md 4.1 kB
test/global.d.ts 41 B
test/tsconfig.json 96 B
tsconfig.base.json 172 B
tsconfig.json 395 B
vercel.json 190 B
vite.config.ts 544 B
vitest.config.ts 342 B

🤖 This report was automatically generated by pkg-size-action

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 2, 2025

Open in StackBlitz

@pkgr/browser

npm i https://pkg.pr.new/@pkgr/browser@416

@pkgr/core

npm i https://pkg.pr.new/@pkgr/core@416

@pkgr/es-modules

npm i https://pkg.pr.new/@pkgr/es-modules@416

@pkgr/imagemin

npm i https://pkg.pr.new/@pkgr/imagemin@416

@pkgr/rollup

npm i https://pkg.pr.new/@pkgr/rollup@416

@pkgr/umd-globals

npm i https://pkg.pr.new/@pkgr/umd-globals@416

@pkgr/utils

npm i https://pkg.pr.new/@pkgr/utils@416

commit: ef22a4a

@github-actions
Copy link
Contributor

github-actions bot commented Jun 2, 2025

Deploy preview for pkgr ready!

✅ Preview
https://pkgr-7i37yi8mb-1stg.vercel.app

Built with commit ef22a4a.
This pull request is being automatically deployed with vercel-action

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 662edc3 in 1 minute and 46 seconds. Click for details.
  • Reviewed 86 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/core/src/helpers.ts:43
  • Draft comment:
    Swallowing fs.statSync errors here may hide unexpected issues. Consider checking for expected error codes (e.g. ENOENT) in the catch block.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% The code is using throwIfNoEntry: false which is the proper way to handle non-existent files. Any other errors would be unexpected filesystem errors like permissions. The function returns undefined on failure which is a clear failure mode. The comment suggests a more complex solution without clear benefit. I could be wrong about error handling best practices. Maybe there are important error cases that should be handled differently. The code's current error handling is appropriate for its purpose - it's a helper that safely checks if a file exists and returns undefined if anything goes wrong. More granular error handling would add complexity without clear benefit. Delete this comment. The current error handling is appropriate and the suggested change would add unnecessary complexity.
2. packages/core/src/helpers.ts:95
  • Draft comment:
    Removal of stop validation logic means the 'stop' option is no longer normalized. Without converting it to an absolute path, comparing it with 'entry' may lead to inconsistencies.
  • Reason this comment was not posted:
    Comment was on unchanged code.

Workflow ID: wflow_yFzZah3wTr2me1jn

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

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 ensures that findUp no longer throws by catching file system errors and removing throw-based options and stop-path validation.

  • Wrapped fs.statSync in tryFileStats inside a try/catch to swallow unexpected errors.
  • Removed throwOnStopNotFound and throwOnInvalidStop options and related stop-path checks in findUp.
  • Simplified findUp signature by removing throw options and the initial entry resolution via tryFileStats.
Comments suppressed due to low confidence (1)

packages/core/src/helpers.ts:99

  • Initial resolution of entry via tryFileStats was removed, so entry may not be normalized to a directory or absolute path. This can cause the upward search to start from an unintended location.
    do {

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8d23d71 and ef22a4a.

📒 Files selected for processing (2)
  • .changeset/giant-trainers-swim.md (1 hunks)
  • packages/core/src/helpers.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/src/helpers.ts (1)
packages/core/src/constants.ts (1)
  • CWD (5-5)
🪛 GitHub Check: codecov/patch
packages/core/src/helpers.ts

[warning] 44-45: packages/core/src/helpers.ts#L44-L45
Added lines #L44 - L45 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on macos-latest
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
🔇 Additional comments (2)
packages/core/src/helpers.ts (1)

95-95:

Details

✅ Verification successful

Simplified destructuring aligns with no-throw objective.

The removal of the throwOnStopNotFound and throwOnInvalidStop options simplifies the function and eliminates potential error paths, which perfectly aligns with making findUp never throw.

Verify that all existing usage of findUp is compatible with the removed options:


🏁 Script executed:

#!/bin/bash
# Description: Search for usage of removed options to ensure compatibility

# Search for any usage of the removed options
rg -A 3 -B 3 "throwOnStopNotFound|throwOnInvalidStop"

# Search for findUp usage patterns to ensure compatibility
rg -A 5 -B 2 "findUp\("

Length of output: 81


To ensure no remaining references to the old options or the findUp API, let’s broaden our search:


🏁 Script executed:

#!/bin/bash
# Re-verify that no call sites or type references remain

# Search for any runtime calls to findUp
rg -n "findUp\(" --color never

# Search for any mention of FindUpOptions in types or docs
rg -n "FindUpOptions" --color never

# Double-check for the removed options
rg -n "throwOnStopNotFound|throwOnInvalidStop" --color never

Length of output: 330


Let’s inspect the FindUpOptions interface to confirm it no longer includes the removed properties:


🏁 Script executed:

#!/bin/bash
# Show the FindUpOptions interface definition
rg -n "export interface FindUpOptions" -A15 -B0 packages/core/src/helpers.ts

Length of output: 457


All outdated options removed and no lingering usage detected.

Verification steps confirmed that:

  • The FindUpOptions interface no longer includes throwOnStopNotFound or throwOnInvalidStop.
  • No calls to findUp( exist outside its own definition.
  • No references to FindUpOptions remain elsewhere in the repo.

This cleanly aligns with the goal of making findUp non-throwing. Feel free to merge.

.changeset/giant-trainers-swim.md (1)

1-6: Well-documented changeset for the patch update.

The changeset correctly follows the standard format and accurately describes the fix. The patch-level version bump is appropriate for this bug fix that ensures findUp never throws.

@JounQin JounQin merged commit 6486aa8 into master Jun 2, 2025
35 of 36 checks passed
@JounQin JounQin deleted the fix/find-up branch June 2, 2025 13:26
@JounQin JounQin mentioned this pull request Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants