apache / apache/cordova-plugin-file

Electron platform - 'Missing Command Error' on API calls

Open
#334 5 comments 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
744
Forks
754
Avg merge
3d 4h
Merged PRs (30d)
1

Description

# Bug Report

## Problem

### What is expected to happen?

File APIs working normally and return a valid Entry or a valid error code.

### What does actually happen?

When invoking any api, it will throw
```javascript
FileError {code: "Missing Command Error", message: undefined}
```
with
```javascript
Error: exec proxy not found for :: File :: $TheAPIYouInvoked
```

### Environment, Platform, Device
`cordova.platformId = 'electron'`
Linux x64, Ubuntu 18.04

## Checklist

- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version

# Suspected Cause
Tracing the error output, I suspect this is caused by inconsistencies in platform detection strategy?

Eg: In [src/browser/FileProxy.js](https://github.com/apache/cordova-plugin-file/tree/master/src/browser) and [www/resolveLocalFileSystemURI.js](https://github.com/apache/cordova-plugin-file/blob/master/www/resolveLocalFileSystemURI.js)
```javascript
//In src/browser/FileProxy.js

// For chrome we don't need to implement proxy methods
// All functionality can be accessed natively.
if (require('./isChrome')()) {
var pathsPrefix = {
// Read-only directory where the application is installed.
applicationDirectory: location.origin + '/', // eslint-disable-line no-undef
// Where to put app-specific data files.
dataDirectory: 'filesystem:file:///persistent/',
// Cached files that should survive app restarts.
// Apps should not rely on the OS to delete files in here.
cacheDirectory: 'filesystem:file:///temporary/'
};

exports.requestAllPaths = function (successCallback) {
successCallback(pathsPrefix);
};

require('cordova/exec/proxy').add('File', module.exports);
return;
}
```
```javascript
//In www/resolveLocalFileSystemURI.js

// For browser platform: not all browsers use overrided `resolveLocalFileSystemURL`.
function checkBrowser () {
if (cordova.platformId === 'browser' && require('./isChrome')()) { // eslint-disable-line no-undef
module.exports.resolveLocalFileSystemURL = window.resolveLocalFileSystemURL || window.webkitResolveLocalFileSystemURL;
return true;
}
return false;
}
if (checkBrowser()) {
return;
}
```
In src/browser/FileProxy.js, it assumes Electron have all the native APIs. So it choose to register nothing in the execProxy of Cordova. Meanwhile, other modules consider Electron not qualified (`cordova.platformId !== 'browser'`) and overrides its methods.

# Fixing Attempt
I've hacked src/browser/FileProxy.js to ensure it uses a consistent platform detection logic
```javascript
//In src/browser/FileProxy.js

// For chrome we don't need to implement proxy methods
// All functionality can be accessed natively.
if (cordova.platformId === 'browser' && require('./isChrome')()) { // FIX HERE

//..........

require('cordova/exec/proxy').add('File', module.exports);
return;
}
```
And at least the API call is OK. No more `Error: exec proxy not found for :: File :: `

Is there anyone who can confirm this issue? I'm not familiar with Cordova platform thus quite unsure about this fix.

Contributor guide

Open the contributing guide

Research direction

Reproduce an Electron file API call and inspect src/browser/FileProxy.js alongside www/resolveLocalFileSystemURI.js, focusing on their platform checks and proxy registration. Compare the Electron and browser paths, then verify that the API returns an Entry or valid error code without an exec proxy-not-found error.

Written by the indexing model from the issue text.

Assessment

Tech stack
electron, javascript
Domain
api, desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.