Skip to content

Conversation

lygstate
Copy link

@lygstate lygstate commented Aug 24, 2024


Acceptance Checklist

  • Story: Code is focused on the linked stories and solves a problem
  • One of:
    • For Bugs: A unit test is added or an existing one modified
    • For Features: New unit tests are added covering the new functions or modifications
  • Code Documentation changes are included for public interfaces and important / complex additions
  • External Documentation is included for API changes, or other external facing interfaces

Review Checklist

  • The code does not duplicate existing functionality that exists elsewhere
  • The code has been linted and follows team practices and style guidelines
  • The changes in the PR are relevant to the title
    • changes not related should be moved to a different PR
  • All errors or error handling is actionable, and informs the viewer on how to correct it

Fixes #377

Summary by CodeRabbit

  • New Features
    • Added a “connect” event for the server, providing connection details and a connection count to listeners.
  • Bug Fixes
    • Options with undefined values are now ignored during initialization to prevent unintended overrides.
  • Refactor
    • Adjusted public exports: default export is FtpServer (FtpSrv alias retained), exposed FtpConnection, and replaced the aggregated error export with individual error types.

node:internal/errors:541
      throw error;
      ^

TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined
    at Url.parse (node:url:170:3)
    at Object.urlParse [as parse] (node:url:141:13)
    at new FtpServer (C:\work\xemu\xemu-bsp-list\ftp-srv\src\index.js:34:24)
    at startFtpServer (C:\work\xemu\xemu-bsp-list\ftp-srv\bin\index.js:133:21)
    at Object.<anonymous> (C:\work\xemu\xemu-bsp-list\ftp-srv\bin\index.js:11:1)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49 {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v20.12.0
@lygstate lygstate force-pushed the main branch 3 times, most recently from 9a09651 to 89846a1 Compare August 24, 2024 04:56
@lygstate lygstate changed the title Remove the need of log in src/index.js fix: fixes "url" argument must be of type string with nodejs 20 Aug 24, 2024
iamart
iamart previously approved these changes Oct 8, 2025
@iamart iamart enabled auto-merge (squash) October 8, 2025 16:45
Copy link

coderabbitai bot commented Oct 8, 2025

Walkthrough

This change updates type declarations (adding a "connect" event overload), refactors CommonJS exports to expose classes and individual errors, and sanitizes options on server construction by removing undefined values. No runtime logic changes beyond options filtering are introduced.

Changes

Cohort / File(s) Summary
Type definitions update
ftp-srv.d.ts
Added FtpServer.on("connect", listener({ connection, id, newConnectionCount })) overload. Reformatted declarations and imports without changing existing signatures.
Exports refactor
ftp-srv.js
Switched default export to FtpServer; kept alias FtpSrv pointing to FtpServer. Added explicit exports: FtpServer, FtpConnection, and individual error classes (GeneralError, SocketError, FileSystemError, ConnectorError). Retained FileSystem export.
Options sanitization
src/index.js
Constructor now filters out undefined values from options (via _.pickBy) before assigning to this.options. Minor formatting changes only.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant Server as FtpServer
  participant Listener as "on('connect', ...)"

  rect rgba(230,240,255,0.5)
    Client->>Server: TCP connection established
    note over Server: Accepts connection
    Server-->>Listener: emit "connect" { connection, id, newConnectionCount }
    note right of Listener: New overload in d.ts
  end

  opt Subsequent flow
    Server-->>Client: Proceed with login/commands
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I thump my paws—new ports unfurled,
A connect squeak echoes through the world.
Exports lined like carrots in a row,
Errors hop out, singly on show.
Options trimmed, no wilted leaves—
A tidy burrow, code that breathes. 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The pull request title refers to fixing a “url” argument type error on Node.js 20 but the changeset only includes API overload additions, export refactoring, option filtering, and formatting tweaks without any modifications related to a URL parameter or Node.js 20 compatibility. Therefore the title does not accurately summarize the actual content of this PR. Please update the title to reflect the actual changes such as formatting adjustments, new event overload, and export updates or otherwise include the intended fix for the URL type error so that the title matches the code modifications.
Linked Issues Check ⚠️ Warning The PR does not implement any changes related to the buyan library or its webpack compatibility as described in issue #377, so it fails to address the core objective of restricting buyan usage to test cases or otherwise resolving that compatibility problem. Ensure that the code changes directly address the buyan compatibility issue—such as limiting buyan imports to test files or adding bundler configuration—before merging this pull request.
Out of Scope Changes Check ⚠️ Warning All modifications in this PR involve formatting adjustments, new event overloads, export refactoring, and option sanitization, none of which relate to either the URL argument fix in the title or the buyan compatibility objective in the linked issue, indicating extensive out-of-scope changes. Refactor this pull request to include only the commits necessary for the stated bug fix or issue resolution and move formatting or API additions into separate, dedicated pull requests.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed The pull request description includes the required “Acceptance Checklist” and “Review Checklist” sections exactly as specified by the repository template and references the linked issue, satisfying the structural requirements of the template.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ 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

@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 (1)
src/index.js (1)

29-29: Filter null values in options
Use _.pickBy(options, v => v != null) to exclude both undefined and null, preventing url.parse(null) from throwing in Node.js 20.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e59aa29 and 7852ee8.

📒 Files selected for processing (3)
  • ftp-srv.d.ts (2 hunks)
  • ftp-srv.js (1 hunks)
  • src/index.js (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/index.js (2)
src/commands/index.js (1)
  • _ (1-1)
src/connection.js (1)
  • _ (1-1)
ftp-srv.d.ts (2)
src/connection.js (2)
  • FileSystem (7-7)
  • EventEmitter (4-4)
src/index.js (2)
  • tls (6-6)
  • EventEmitter (7-7)
🔇 Additional comments (2)
ftp-srv.d.ts (1)

1-190: Formatting improvements enhance readability.

The formatting changes throughout this file (consistent semicolons, multi-line signatures, aligned indentation) improve code readability without altering semantic types. These changes complement the API surface expansion in ftp-srv.js.

ftp-srv.js (1)

1-14: Reintroduce or document group error export and separate API refactor from bug fix

  • The aggregate errors/ftpErrors export was removed in ftp-srv.js, breaking any consumers doing require('ftp-srv').errors; re-add module.exports.errors = errors (or alias ftpErrors) and note this in a migration guide.
  • The export changes are unrelated to the Node.js 20 URL fix—split them into a dedicated PR or update the title/description to cover both changes.

Comment on lines +169 to +172
on(
event: "connect",
listener: (data: { connection: FtpConnection; id: string; newConnectionCount: number }) => void
): this;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

LGTM! The connect event overload aligns with runtime behavior.

The new on("connect", listener) overload correctly declares the event emitted at line 57 in src/index.js, providing proper TypeScript support for the connect event handler.

Verify that all event emissions in the runtime code have corresponding type declarations:


🏁 Script executed:

#!/bin/bash
# Find all emit calls in src/index.js and verify they have type declarations
rg -nP --type=js 'this\.emit\(' src/index.js

# Check for any other event emitters in the codebase
rg -nP --type=js 'this\.emit\(' src/

Length of output: 1256


#!/bin/bash
evs=(disconnect connect server-error closing closed STOR RNTO RETR)
for ev in "${evs[@]}"; do
if rg -nP "on\(\sevent:\s"$ev"" ftp-srv.d.ts > /dev/null; then
echo "$ev: declared"
else
echo "$ev: missing"
fi
done


#!/bin/bash

Check for event overload declarations in ftp-srv.d.ts

evs=(disconnect connect server-error closing closed STOR RNTO RETR)
for ev in "${evs[@]}"; do
echo -n "$ev: "
rg -nP "on(\sevent:\s"$ev"" ftp-srv.d.ts || echo "missing"
done


🏁 Script executed:

#!/bin/bash
evs=(disconnect connect "server-error" closing closed STOR RNTO RETR)
for ev in "${evs[@]}"; do
  if rg -nP "on\\(\\s*event:\\s*\"$ev\"" ftp-srv.d.ts; then
    echo "$ev: declared"
  else
    echo "$ev: missing"
  fi
done

Length of output: 133


🏁 Script executed:

#!/bin/bash
FILE=$(find . -type f -name "ftp-srv.d.ts" | head -1)
echo "Path: $FILE"
sed -n '150,200p' "$FILE"

Length of output: 920


Add missing event overloads
ftp-srv.d.ts currently covers login, connect, disconnect, and client-error but omits the following runtime-emitted events in src/index.js:

  • "server-error" (payload { error: Error })
  • "closing" (no payload)
  • "closed" (no payload)

Additionally, command-level emits in src/commands/registration ("STOR", "RNTO", "RETR") need corresponding on(event, listener) overloads on the FtpConnection type.

🤖 Prompt for AI Agents
In ftp-srv.d.ts around lines 169–172, add missing event overloads and
command-level emits: add on(event: "server-error", listener: (data: { error:
Error }) => void): this; add on(event: "closing", listener: () => void): this;
add on(event: "closed", listener: () => void): this; and on the FtpConnection
type add overloads for command-level emits on("STOR", listener: (data: any) =>
void): this; on("RNTO", listener: (data: any) => void): this; on("RETR",
listener: (data: any) => void): this; ensuring signatures match the runtime
payloads in src/index.js and src/commands/registration (replace any with more
specific types if present in those files).

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.

buyan is not compat with webpack, can we make use of buyan only in testcase?
2 participants