Skip to content

Comments

Fix silent error handling in FTP listener#1549

Merged
niveathika merged 5 commits intomasterfrom
fix-silent-error-handling
Feb 15, 2026
Merged

Fix silent error handling in FTP listener#1549
niveathika merged 5 commits intomasterfrom
fix-silent-error-handling

Conversation

@niveathika
Copy link
Contributor

@niveathika niveathika commented Feb 14, 2026

Summary

  • Add upfront regex pattern validation in FormatMethodsHolder
  • Replace log.error with BError.printStackTrace for visible errors
  • Remove redundant code in FtpListener

Problem

Native side log.error() calls are not visible to users, causing the FTP listener to silently fail in various error scenarios.

Solution

Changed to create BError and call printStackTrace() which outputs Ballerina-formatted errors that are visible to users.

Fixes: ballerina-platform/ballerina-library#8655

🤖 Generated with Claude Code

Summary

This pull request improves error visibility and early configuration validation in the FTP listener so configuration and runtime problems are reported clearly to users instead of being silently lost.

Changes

  • Error reporting: Replaced native-side log.error calls with Ballerina-formatted errors (FtpUtil.createError(...) and BError.printStackTrace()) across server and client native code (including FtpContentCallbackHandler, FtpListener, client helpers and related utilities) so native errors are surfaced to users in a consistent, visible format.
  • Early validation: Added upfront regex validation for @ftp:FunctionConfig.fileNamePattern in FormatMethodsHolder during initialization to surface invalid patterns at startup and removed redundant runtime pattern exception handling.
  • Cleanup: Removed or simplified redundant logging and error-checking paths and centralized error creation via FtpUtil to streamline error handling and reduce silent failures.
  • Changelog: Added an unreleased note describing the fix for silent listener failures.

Outcome

Improves stability and debuggability of the FTP listener by surfacing configuration and runtime errors in a consistent, user-visible format and by catching invalid filename patterns earlier during initialization.

@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2026

📝 Walkthrough

Walkthrough

Validates fileNamePattern regexes at initialization and shifts many runtime logger log.error calls to use FtpUtil.createError(...).printStackTrace() or direct error.printStackTrace(), removing several inline logging statements and related try/catch logging in FTP client/server utilities.

Changes

Cohort / File(s) Summary
Pattern Validation at Init
native/src/main/java/io/ballerina/stdlib/ftp/server/FormatMethodsHolder.java
Adds FtpUtil.validateRegexPattern when registering fileNamePattern from annotations and removes the runtime try/catch around Pattern.matches, relying on initialization-time validation.
Server-side Error Handling
native/src/main/java/io/ballerina/stdlib/ftp/server/FtpContentCallbackHandler.java, native/src/main/java/io/ballerina/stdlib/ftp/server/FtpListener.java
Replaces many log.error calls with FtpUtil.createError(...).printStackTrace() or error.printStackTrace() in async and sync error paths; simplifies legacy onFileChange fallback and removes some runtime parameter-type error logs.
Client-side & Utilities
native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClientHelper.java, native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClientListener.java, native/src/main/java/io/ballerina/stdlib/ftp/util/FtpContentConverter.java, native/src/main/java/io/ballerina/stdlib/ftp/util/FtpUtil.java
Removes several log.error calls in client listeners/helpers and content converters; some exceptions now complete/return errors without logging. FtpUtil.extractPortValue no longer logs an invalid-port error (still returns -1).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐇 I hopped through patterns, snug and tight,
I checked each regex in the night,
When errors came I let them show,
Stack traces sparkling in a row,
Hooray — the FTP burrow’s just right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (8 files):

⚔️ changelog.md (content)
⚔️ native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClientHelper.java (content)
⚔️ native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClientListener.java (content)
⚔️ native/src/main/java/io/ballerina/stdlib/ftp/server/FormatMethodsHolder.java (content)
⚔️ native/src/main/java/io/ballerina/stdlib/ftp/server/FtpContentCallbackHandler.java (content)
⚔️ native/src/main/java/io/ballerina/stdlib/ftp/server/FtpListener.java (content)
⚔️ native/src/main/java/io/ballerina/stdlib/ftp/util/FtpContentConverter.java (content)
⚔️ native/src/main/java/io/ballerina/stdlib/ftp/util/FtpUtil.java (content)

These conflicts must be resolved before merging into master.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix silent error handling in FTP listener' accurately and concisely describes the main objective of the PR.
Description check ✅ Passed The description covers Purpose (problem and solution), includes a changelog entry, and links to the issue, meeting the core template requirements.
Linked Issues check ✅ Passed All required changes from issue #8655 are implemented: regex pattern validation in FormatMethodsHolder, replacing log.error with BError.printStackTrace in FormatMethodsHolder, FtpContentCallbackHandler, FtpListener, FtpClientHelper, FtpClientListener, and FtpUtil.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #8655; changelog updates and code modifications are all within the stated objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-silent-error-handling
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch fix-silent-error-handling
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

No actionable comments were generated in the recent review. 🎉


Comment @coderabbitai help to get the list of available commands and usage tips.

Validate @ftp:FunctionConfig.fileNamePattern regex patterns during
initialization rather than catching errors at runtime.
Native side log.error() calls are not visible to users, causing
silent failures. Changed to create BError and call printStackTrace()
for Ballerina-formatted error output.
Replace log.error with BError.printStackTrace for visible error output.
@niveathika niveathika force-pushed the fix-silent-error-handling branch from e36b6fc to c17d593 Compare February 14, 2026 17:44
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

🤖 Fix all issues with AI agents
In `@native/src/main/java/io/ballerina/stdlib/ftp/server/FtpListener.java`:
- Around line 171-175: The fallback branch currently calls
onFileChangeMethodType.get() which can throw if absent; update FtpListener to
first check Optional.isPresent() for the result of
getOnFileChangeMethod(service) and only call
processMetadataOnlyCallbacks(service, event, onFileChangeMethodType.get(),
caller) when present; if not present, handle defensively (e.g., log a clear
warning/error with context using the existing logger and return or skip
processing) so there is no uncaught NoSuchElementException.

@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

❌ Patch coverage is 12.50000% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.61%. Comparing base (4a0c824) to head (866fed5).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
...a/stdlib/ftp/server/FtpContentCallbackHandler.java 0.00% 16 Missing ⚠️
...va/io/ballerina/stdlib/ftp/server/FtpListener.java 20.00% 4 Missing ⚠️
...llerina/stdlib/ftp/server/FormatMethodsHolder.java 66.66% 0 Missing and 1 partial ⚠️

❌ Your project status has failed because the head coverage (76.61%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1549      +/-   ##
============================================
+ Coverage     76.53%   76.61%   +0.07%     
  Complexity     1043     1043              
============================================
  Files            76       76              
  Lines          4833     4823      -10     
  Branches        838      837       -1     
============================================
- Hits           3699     3695       -4     
+ Misses          760      755       -5     
+ Partials        374      373       -1     

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

@niveathika niveathika merged commit 883221b into master Feb 15, 2026
6 of 9 checks passed
@niveathika niveathika deleted the fix-silent-error-handling branch February 16, 2026 08:22
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.

[ftp] Listener silently fails when errors occur - native log.error() calls are not visible

2 participants