danielsogl/awesome-cordova-plugins

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

Closed this issue · 2 comments

fudom commented

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 commented

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);
}
});
}

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