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

CB-14181: (android) Fix bug - Cannot read property 'filesystemName' of null #235

Merged
merged 2 commits into from
Jun 30, 2018

Conversation

jony89
Copy link
Contributor

@jony89 jony89 commented Jun 28, 2018

fix error :

Error in Success callbackId: File1539060614 : TypeError: Cannot read property 'filesystemName' of null
cordova.js:314 Uncaught TypeError: Cannot read property 'filesystemName' of null

The fsRoot might be null. reproduced with latest cordova on android emulator.

Platforms affected

What does this PR do?

What testing has been done on this change?

Checklist

fix error :

Error in Success callbackId: File1539060614 : TypeError: Cannot read property 'filesystemName' of null
cordova.js:314 Uncaught TypeError: Cannot read property 'filesystemName' of null

The `fsRoot` might be null. reproduced with latest cordova on android emulator.
@jony89 jony89 changed the title fix: Cannot read property 'filesystemName' of null CB-14181: (android) Fix bug - Cannot read property 'filesystemName' of null Jun 28, 2018
@shazron
Copy link
Member

shazron commented Jun 29, 2018

There are eslint issues with this patch, see Travis CI build logs. Run npm test you will see them.

@jony89
Copy link
Contributor Author

jony89 commented Jun 29, 2018

fixed, yet I see tests are failing and they fail in all other PR's as well.

@jcesarmobile
Copy link
Member

This will prevent the error, but what will cause the "Cannot read property 'filesystemName' of null"? How can this be reproduced?

@jony89
Copy link
Contributor Author

jony89 commented Jun 29, 2018

@jcesarmobile it has been reproduced to me constantly on android emulator nexus 5

device - nexus 5
android 7.1.1 nougat (yet will be reproduced on oreo as well I'm sure)
cordova 7.1.0

with the following code from the blog - documentation (caused on the line fs.root.getFile

        window.requestFileSystem(window.LocalFileSystem.TEMPORARY, 0, (fs) => {
            console.log('file system open: ' + fs.name);
            fs.root.getFile(
                `${window.cordova.file.applicationStorageDirectory}${this.fileName}`, { create: true, exclusive: false }, (fileEntry) => {
                    console.log('fileEntry is file? ' + fileEntry.isFile.toString());
                    var oReq = new XMLHttpRequest();
                    // Make sure you add the domain name to the Content-Security-Policy <meta> element.
                    oReq.open('GET', cvURL, true);
                    // Define how you want the XHR data to come back
                    oReq.responseType = 'blob';
                    oReq.onload = (oEvent) => {
                        var blob = oReq.response; // Note: not oReq.responseText
                        if (blob) {
                        // Create a URL based on the blob, and set an <img> tag's src to it.
                            var url = window.URL.createObjectURL(blob);
                            document.getElementById('bot-img').src = url;
                            // Or read the data with a FileReader
                            var reader = new FileReader();
                            reader.addEventListener('loadend', () => {
                            // reader.result contains the contents of blob as text
                            });
                            reader.readAsText(blob);
                        } else console.error('we didnt get an XHR response!');
                    };
                    oReq.send(null);
                }, function (err) { console.error('error getting file! ' + err); });
        }, function (err) { console.error('error getting persistent fs! ' + err); });

@jcesarmobile
Copy link
Member

I couldn't reproduce with that code on real devices or the emulator.
Anyway, the code is ok, going to merge.

But what should worry us is why root is null on first place.
As you can reproduce, would be good if you can investigate and create a new issue with more information about what might cause the root to be null.

@jcesarmobile jcesarmobile merged commit cc3aedb into apache:master Jun 30, 2018
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.

3 participants