Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Old cordova/ionic app help #1463

Open
Ju66ernaut opened this issue Dec 19, 2019 · 0 comments
Open

Old cordova/ionic app help #1463

Ju66ernaut opened this issue Dec 19, 2019 · 0 comments

Comments

@Ju66ernaut
Copy link

I am aware this is a long shot but I am in a bind with a project with no real hope of being able to update or upgrade.

I am working on an old cordova/ionic app (the ng-cordova.js says it is v0.1.27-alpha)

This app downloads html files and loads them with
$cordovaFile.readAsText(cordova.file.dataDirectory, fileName)

Up until recently this has worked fine with standalone html files. By standalone I mean its as if the page was loaded from the file system and requires no connectivity once its loaded. One file in particular was working and now isn't with (seemingly) nothing notable that changed.

I narrowed down the issue to line 2867 of ng-cordova.js where the handler for reader.onloadend is assigned.

readAsText: function (path, file) {
          var q = $q.defer();
​
          if ((/^\//.test(file))) {
            q.reject('file-name cannot start with \/');
          }
​
          try {
            $window.resolveLocalFileSystemURL(path, function (fileSystem) {
              fileSystem.getFile(file, {create: false}, function (fileEntry) {
                fileEntry.file(function (fileData) {
                  var reader = new FileReader();
​
                  reader.onloadend = function (evt) {
                  // line 2867
                    if (evt.target.result !== undefined || evt.target.result !== null) {
                      q.resolve(evt.target.result);
                    } else if (evt.target.error !== undefined || evt.target.error !== null) {
                      q.reject(evt.target.error);
                    } else {
                      q.reject({code: null, message: 'READER_ONLOADEND_ERR'});
                    }
                  };
​
                  reader.readAsText(fileData);
                });
              }, function (error) {
                error.message = $cordovaFileError[error.code];
                q.reject(error);
              });
            }, function (err) {
              err.message = $cordovaFileError[err.code];
              q.reject(err);
            });
          } catch (e) {
            e.message = $cordovaFileError[e.code];
            q.reject(e);
          }
​
          return q.promise;
        },

The problem is the reader is returning null whereas before (I am guessing) it was returning the correct html string. And since the null value is technically correct, (because its !undefined OR !null) its not throwing any errors and if I try to step into the reader code the app and dev tools crash.

Any help with this would be greatly appreciated as I have been spinning my wheels with this for days.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant