Skip to content
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

[File] checkFile fails if file does not exist, instead of resolve boolean. #4689

Closed
fudom opened this issue Dec 12, 2023 · 2 comments
Closed

Comments

@fudom
Copy link

fudom commented Dec 12, 2023

Bug Report

Current behavior:

checkFile rejects if file does not exist.

Expected behavior:

Resolve to boolean as described in type Promise<boolean>. false: Does not exist. true: File exists.

checkFile(path: string, file: string): Promise<boolean> {

Steps to reproduce:

const exists = await this.file.checkFile(path, name);

Android 13, cordova-plugin-file 8.0.1, @awesome-cordova-plugins/file 6.4.0

@fudom
Copy link
Author

fudom commented Dec 21, 2023

What is this? I mean code like Promise.reject<boolean>(new Error()). In what world is an Error a Boolean? And why define return type Boolean (in Promise) when you reject instead of resolve(false)? Use Promise<void> instead or do it right. It's messy. Or what is the reason behind?

checkFile(path: string, file: string): Promise<boolean> {
if (/^\//.test(file)) {
const err = new FileError(5);
err.message = 'file cannot start with /';
return Promise.reject<any>(err);
}
return this.resolveLocalFilesystemUrl(path + file).then((fse) => {
if (fse.isFile) {
return true;
} else {
const err = new FileError(13);
err.message = 'input is not a file';
return Promise.reject<boolean>(err);
}
});
}

Copy link

There has been no recent activity and this issue has been marked inactive.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant