Skip to content

Comments

Fix missing error handling in file:copy for non-existent destination directory#576

Merged
niveathika merged 2 commits intoballerina-platform:masterfrom
DharshiBalasubramaniyam:file-copy-to-non-exist-target-fix
Oct 7, 2025
Merged

Fix missing error handling in file:copy for non-existent destination directory#576
niveathika merged 2 commits intoballerina-platform:masterfrom
DharshiBalasubramaniyam:file-copy-to-non-exist-target-fix

Conversation

@DharshiBalasubramaniyam
Copy link
Contributor

@DharshiBalasubramaniyam DharshiBalasubramaniyam commented Oct 3, 2025

Purpose

Fixes ballerina-platform/ballerina-library#5738

Examples

With the implementation of this PR, the code below returns FileNotFoundError if the directory foo does not exist.

import ballerina/file;
import ballerina/io;

public function main() returns error? {
    string sourcePath = "insert.sql";
    string destPath = "foo/insert.sql";
    file:Error? copy = file:copy(sourcePath, destPath);
    if copy is file:Error {
        io:println(copy.message());
    }
}

Output for the above code:

The target directory does not exist: insert.sql -> foo/insert.sql"

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests
  • Updated the spec
  • Checked native-image compatibility

@CLAassistant
Copy link

CLAassistant commented Oct 3, 2025

CLA assistant check
All committers have signed the CLA.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 3, 2025

@codecov
Copy link

codecov bot commented Oct 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.64%. Comparing base (682cc08) to head (58d34be).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #576      +/-   ##
============================================
+ Coverage     82.20%   82.64%   +0.43%     
  Complexity       91       91              
============================================
  Files            18       18              
  Lines           770      772       +2     
  Branches        164      164              
============================================
+ Hits            633      638       +5     
+ Misses          118      115       -3     
  Partials         19       19              

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

@daneshk
Copy link
Member

daneshk commented Oct 5, 2025

@niveathika can you check.

@DharshiBalasubramaniyam
Copy link
Contributor Author

DharshiBalasubramaniyam commented Oct 7, 2025

Hi @niveathika, please check this when you are available and inform me of any required changes.

Thanks

Copy link
Contributor

@niveathika niveathika left a comment

Choose a reason for hiding this comment

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

LGTM

@niveathika niveathika merged commit ad65395 into ballerina-platform:master Oct 7, 2025
8 checks passed
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.

file:copy does not create missing directories in destination path

4 participants