You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 19, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 19, 2024. It is now read-only.
Reprising your sample and introducing an obvious mistake shows that errors don't seem to escape promise handlers:
var uwp = require('uwp');
uwp.projectNamespace("Windows");
Windows.Storage.KnownFolders.documentsLibrary.createFileAsync(
"sample.dat", Windows.Storage.CreationCollisionOption.replaceExisting)
.done(
function (file) {
undefinedFunc();
},
function (error) {
undefinedFunc();
}
);
Running this shows no error, it just runs eternally because uwp.close() is never called. It makes it hard to detect errors, especially programming ones.
I read about WinJS.promise.onerror, but I'm not sure how it relates to the uwp module. Any pointers?
Hugo Wood (@hgwood) , I would go with .then().done() approach as given below. I verified that this lets you catch the errors and close the uwp.
varuwp=require('uwp');uwp.projectNamespace("Windows");Windows.Storage.KnownFolders.documentsLibrary.createFileAsync("sample.dat",Windows.Storage.CreationCollisionOption.replaceExisting).then(function(file){undefinedFunc();},function(error){undefinedFunc();}).done(function(result){},function(error){console.log('handle all the errors');uwp.close();// close uwp});
That's a nice work-around thanks, but wouldn't you say the original problem is a bug? Shouldn't done make its callback throw freely? Isn't that its main difference to then? I guess my real question is: could it be fixed in future versions?
Sorry if I add clutter to the conversation but it surprise me to see the .done() method in a Promise outside jQuery. There is no mention of a .done() method in the JS language specification.
Off the top of my head, I can only think of the following similar cases for JS Promises:
// Thenable throws before callback// Promise rejectsvarthenable={then: function(resolve){thrownewTypeError("Throwing");resolve("Resolving");}};varp1=Promise.resolve(thenable);p1.then(function(v){thrownewError("Should not be called");// not called},function(e){console.log(e);// TypeError: Throwing});// Thenable throws after callback// Promise resolvesvarthenable={then: function(resolve){resolve("Resolving");thrownewTypeError("Throwing");}};varp2=Promise.resolve(thenable);p2.then(function(v){console.log(v);// "Resolving"},function(e){thrownewError("Should not be called");// not called});
Activity
kunalspathak commentedon Jan 25, 2016
Thanks Hugo Wood (@hgwood) for reporting this. I will investigate this and get back to you.
kunalspathak commentedon Jan 25, 2016
Hugo Wood (@hgwood) , I would go with .then().done() approach as given below. I verified that this lets you catch the errors and close the uwp.
hgwood commentedon Jan 26, 2016
That's a nice work-around thanks, but wouldn't you say the original problem is a bug? Shouldn't
donemake its callback throw freely? Isn't that its main difference tothen? I guess my real question is: could it be fixed in future versions?dotnetCarpenter commentedon Feb 7, 2016
Sorry if I add clutter to the conversation but it surprise me to see the
.done()method in a Promise outside jQuery. There is no mention of a.done()method in the JS language specification.Following the links from MSDN leads to a deprecated test suit for Promises/A.
AFAIK the list is:
Is the exact behavior of
.done()documented anywhere?dotnetCarpenter commentedon Feb 7, 2016
Off the top of my head, I can only think of the following similar cases for JS Promises:
hgwood commentedon Feb 8, 2016
Jon Ege Ronnenberg (@dotnetCarpenter)
doneis present in Bluebird, with the same semantics, but its usage is discouraged.