let nasPath = "";
return getFamInfo(args.familyID)
.then(function (famInfo) {
nasPath = //some code involving famInfo here
return getSFTPConnection(config.nasSettings);
}).then(function (sftp) {
const fastPutProm = Promise.promisify(sftp.fastPut);
return fastPutProm(config.jpgDirectory, nasPath, {});
});
If I put a breakpoint after const fastPutProm = Promise.promisify(sftp.fastPut);, fastPutProm is a function with three arguments. But when I try to run this code, I get a TypeError: Cannot read property 'fastPut' of undefined error. What am I doing wrong here?
That error means that your sftp value is undefined so when you try to pass sftp.fastPut to the promisify() method, it generates an error because you're trying to reference undefined.fastPut which is a TypeError.
So, the solution is to back up a few steps and figure out why sftp doesn't have the desired value in it.
Another possibility is that the error is coming from inside the module and it's because the implementation of sftp.fastPut is referencing this which it expects to be sftp. Your method of promisifying is not preserving the value of this. You can fix that by changing your code to:
const fastPutProm = Promise.promisify(sftp.fastPut, {context: sftp});
Related
I am using angularFireStorage (in my Ionic app).
I am having some success, for instance, I can look at my console.log(res) to click the link in my console to view a belt image. I cannot save it to a variable however, which is the issue. Ultimately I would like to use the image tag and link the belt image using src. Here is my code:
const ref = this.storage.ref('belts/');
ref.listAll().subscribe(belt=>
belt.items.forEach(item=> printImage(item))
)
function printImage(imageRef){
let temp = imageRef.getDownloadURL();
temp.then(res=> {
console.log(res)
this.mySRCs.push(res)
})
}
and how I am testing it.
<img [src]="sanitizer.bypassSecurityTrustResourceUrl(mySRCs[0])"/>
and the error:
Uncaught (in promise): TypeError: Cannot read property 'mySRCs' of undefined
TypeError: Cannot read property 'mySRCs' of undefined
I feel like I did something similar a month or two ago but this time I cannot see the image in my app. Thanks for your help.
I think your issue is with using the 'this' keyword within your 'printImage' function.
You either need to do:
belt.items.forEach(item=> printImage.bind(this, item))
or assuming you have a...
const mySRCs = [];
then you just pass the field as an argument to the printImage function...
belt.items.forEach(item=> printImage(item, mySRCs))
and instead of using 'this' inside the function, you use...
function printImage(imageRef, mySRCs){
let temp = imageRef.getDownloadURL();
temp.then(res=> {
console.log(res)
mySRCs.push(res) //<--- remove this
})
}
According to the documentation here, it should be possible get an id for a not-yet-created firestore document, add it the object to be saved, and then persist it like this:
// Add a new document with a generated id.
var newCityRef = db.collection("cities").doc();
// later...
newCityRef.set(data);
In my application, I follow this pattern with the following code:
async createNewProject(projectObject : Project) : Promise<boolean> {
let doc = this.firestore.collection("projects").doc();
projectObject.id = doc.ref.id;
try {
await doc.set(projectObject);
} catch(err) {
console.error(err);
return false;
}
return true;
}
When it runs though, i get an error in the console:
FirebaseError: Function CollectionReference.doc() requires its first argument to be of type non-empty string, but it was: undefined
Can anybody shed any light? I've seen other folks on her referencing this method (using the doc method with no parameters as the solution to the problem, yet others are seeing this error. Is this some kind of API on the Angular implementation of the API, or a problem at the firebase side of things (or did I do something wrong?)
The doc() method returns a DocumentReference, which does not have a ref property but has an id one. Therefore you need to do:
projectObject.id = doc.id;
instead of
projectObject.id = doc.ref.id;
I created a react-app which I deployed online with npm run build, now everything locally works fine but when I try to load a page on my app it gives a error in Container.js ( no idea what this file is and what it does )
i've tried to reinstall all the node_modules without any result so I cloned my repo fresh but still without any result
Container.js:
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _reactRedux = require('react-redux');
var _Container = require('../components/Container');
var _Container2 = _interopRequireDefault(_Container);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
/**
* src/containers/Container.jsx
*/
var mapStateToProps = function mapStateToProps(store, ownProps) {
return {
items: store[ownProps.reduxStoreName].content[ownProps.reduxUid].filter(function (item) {
return item.parentId === ownProps.itemId;
})
};
};
exports.default = (0, _reactRedux.connect)(mapStateToProps)(_Container2.default);
Error in console: Uncaught (in promise) TypeError: Cannot read property 'filter' of undefined
well, like #Pointy mentioned in his comment, it basically means that store[ownProps.reduxStoreName].content[ownProps.reduxUid] is undefined.
It is not the file which is causing the error, its the specific line. When the code reaches this line and tries to execute it- that store[ownProps.reduxStoreName].content[ownProps.reduxUid] parameter is undefined so it crushes.
We cannot tell you where the error is, we'd need the code of your whole app to follow the execution flow.
You have to follow it yourself, and understand why there is not an array in that variable when the code gets there.
As a general idea, try figure out the following:
when and where that variable is initialized?
when and where do you call mapStateToProps?
are you absolutely sure that the code which answers question 1 is executed before the code which answers to question 2? (maybe there is an asynchronous execution problem you didn't think about which causes your code to execute at the wrong order)
if it does- maybe the way you initialize those variables at the beggining is not correct? maybe you use a 3rd party library / function to initialize them, but not actually getting the result you expecting? or maybe you're using it wrong, or parsing the result wrong?
I'm using Protractor and TypeScript to drive e2e regression
element
<strong _ngcontent-jwu-49="" data-protractor="StreamId">11107</strong>'
case
I need to extract ID from an element and construct a URL out of a string and ID
no matter what I do, a promise is not getting resolved
here is what I've tried
function getStreamId() {
//browser.ignoreSynchronization = true;
var streamIdElement = $$("[data-protractor='StreamId']")
var streamId = streamIdElement.getText().then(
function(text){
browser.get('https://URL/page/'+text);
console.log(streamId)
})
still a promise
and
browser.executeScript("var text = document.querySelectorAll('[data-
protractor='StreamId']').innerHtml").then(function(text)
{console.log(text);});
fails WebDriverError: unknown error: Runtime.evaluate threw exception:
SyntaxError: missing ) after argument list
My question is 2 part one:
what is the best practice in protractor if a value needs to be extracted and interacted with later
is it even possible to resolve a promise into a string (not to read it in the log with .then(function(text){console.log(text)}), so I can assign it to a variable and use it later on)
Your first attempt is actually quite close to the end result. You've located the element, called the getText() and resolved the promise.
Make the function return a promise and resolve once you need an actual value:
function getStreamId() {
var streamIdElement = $$("[data-protractor='StreamId']")
return streamIdElement.getText();
}
getStreamId().then(function(streamId) {
browser.get('https://URL/page/'+streamId);
console.log(streamId);
});
function Notify(header,content,image){
var note = webkitNotifications.createNotification(image||"",header,content);
note.show();
return note;}
var extensions = ["pbjhaapnigfhipfahcfkeakpcgkmnklc"];
function CheckReload(){
for(var CN=0;CN<extensions.length;CN++){
var id = extensions[CN];
var ex = chrome.management.get(id);
console.log("Checking",ex,"-",id);
if(!ex.enabled){
Notify("Extension reloaded!",ex.name+" was found crashed, and reloaded!");
chrome.management.setEnabled(id,true);
}
}
}
setInterval(CheckReload,1000);
Ok, so what I was expecting was for this to check the extensions in the "extensions" array, and if they weren't enabled it would create a notification saying that it wasn't, and then enable it.
However, chrome.management.get(id) seems to be returning undefined.
I expected an output like:
Checking Object - [id]
Instead, what I got was:
Checking undefined - pbjhaapnigfhipfahcfkeakpcgkmnklc
Uncaught TypeError: Cannot read property 'enabled' of undefined
How can I fix this?
Most of the methods provided by chrome don't return a value, instead they take a callback function as a parameter, and call that function with the wanted result.
You should replace your code by
chrome.management.get(id, function(ex) {
console.log("Checking",ex,"-",id);
if(!ex.enabled){
Notify("Extension reloaded!",ex.name+" was found crashed, and reloaded!");
chrome.management.setEnabled(id,true);
}
});
See http://developer.chrome.com/extensions/management.html#method-get for details.
If you are running your code from an extensions, make sure that your extension have permissions to management.