I have a simple Express App communicating with another over gRPC, it appears to be crashing on an error event.
events.js:167
throw er; // Unhandled 'error' event
^
Error: 2 UNKNOWN: Stream removed
at Object.exports.createStatusError (/home/justin/singles-api/node_modules/grpc/src/common.js:91:15)
at ClientReadableStream._emitStatusIfDone (/home/justin/singles-api/node_modules/grpc/src/client.js:233:26)
at ClientReadableStream._receiveStatus (/home/justin/singles-api/node_modules/grpc/src/client.js:211:8)
at Object.onReceiveStatus (/home/justin/singles-api/node_modules/grpc/src/client_interceptors.js:1272:15)
at InterceptingListener._callNext (/home/justin/singles-api/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/home/justin/singles-api/node_modules/grpc/src/client_interceptors.js:618:8)
at /home/justin/singles-api/node_modules/grpc/src/client_interceptors.js:1029:24
Emitted 'error' event at:
at ClientReadableStream._emitStatusIfDone (/home/justin/singles-api/node_modules/grpc/src/client.js:234:12)
at ClientReadableStream._receiveStatus (/home/justin/singles-api/node_modules/grpc/src/client.js:211:8)
[... lines matching original stack trace ...]
at /home/justin/singles-api/node_modules/grpc/src/client_interceptors.js:1029:24
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! singles-api#0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the singles-api#0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I'm using some minimal example code for gRPC, how would I go about handling this to prevent the crash? as I'm not quite sure what it is i'm trying to prevent, presumably just a broken/restarting stream?
var lnrpcDescriptor = grpc.load("./rpc.proto");
var lnrpc = lnrpcDescriptor.lnrpc;
var lnd = new lnrpc.Lightning(hostport, credentials);
var call = lnd.subscribeInvoices(request)
call.on('data', function(response) {
if (response.settle_index === '0') {
console.log("New Invoice Issued: " + response.payment_request)
}
else {
//iterate through array to find who paid their invoice and update the db
for (var i = 0; i < loadedDB.db.Node.length; i++) {
if (loadedDB.db.Node[i].add_index == response.add_index) {
console.log("Node " + loadedDB.db.Node[i].Id + " has settled their invoice.");
loadedDB.db.Node[i].isSettled = true;
saveDB.writeEntry();
}
}
}
});
call.on('status', function(status) {
console.log(status);
});
call.on('end', function() {
console.log('subscribeInvoices stream ended')
});
Related
Still learning firestore, i want to write a function which would create multiple documents upon the creation of a collection at once. So i wrote this code to try it out. i saw the code as an answer to something similar.
const fsRef = admin.firestore();
export const moreCreations = functions.firestore
.document(
"dev_env/schools/school_collections/KithAndKin7394/students/{userID}"
)
.onCreate((snap, context) => {
const newSchoolRef = fsRef
.collection("dev_env")
.doc("schools")
.collection("school_collections")
.doc("KithAndKin7394")
.collection("students")
.doc(snap.id);
// Trying something on documents
const documentIds = [
'CRK_IRK',
'PHE',
'agricScience',
'basicScience',
'basicTechnology',
'businessStudies',
'computerStudies',
'creativeArts',
'english',
'frenchLanguage',
'hausaLanguage',
'homeEconomics',
'iboLanguage',
'maths',
'socialStudies',
'yoruba'
];
const batch = fsRef.batch();
const data ={};
const setbatch = documentIds.forEach(docId => {
batch.set(newSchoolRef.collection('JSS1').doc('${docId}'), data);
})
batch. commit().then(response => {
console.log('Success');
}).catch(err => {
console.error(err);
})
});
I am getting these errors:
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions# lint C:\brighterbrains\functions
> tslint --project tsconfig.json
ERROR: C:/brighterbrains/functions/src/index.ts:168:23 - Expression has type `void`. Put it on its own line as a statement.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions# lint: `tslint --project tsconfig.json`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the functions# lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\dell\AppData\Roaming\npm-cache\_logs\2020-03-30T02_04_34_455Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code2
What i want is when the collection "JSS1" is created, the documents "documentsId" are added to it at once. The code is from this forum but it is not working. Please can anyone point my mistake and help with me with the corrections? The documentation doesn't do or say anything about such actions.
Thanks in advance.
Remove const setbatch = from before the forEach(). It doesn't have a return value.
I have solved it. Below is the updated code:
export const moreCreations = functions.firestore
.document(
"dev_env/schools/school_collections/KithAndKin7394/students/{userID}"
)
.onCreate((snap, context) => {
const newSchoolRef = fsRef
.collection("dev_env")
.doc("schools")
.collection("school_collections")
.doc("KithAndKin7394")
.collection("students")
.doc(snap.id);
// Trying something on documents
const documentIds = [
'CRK_IRK',
'PHE',
'agricScience',
'basicScience',
'basicTechnology',
'businessStudies',
'computerStudies',
'creativeArts',
'english',
'frenchLanguage',
'hausaLanguage',
'homeEconomics',
'iboLanguage',
'maths',
'socialStudies',
'yoruba'
];
const batch = fsRef.batch();
const data ={};
documentIds.forEach(docId => {
batch.set(newSchoolRef.collection('JSS1').doc(docId), data);
})
batch.commit().then(response => {
console.log('Success');
}).catch(err => {
console.error(err);
})
});
It deployed successfully and upon creation of a document, the collection JSS1 is automatically created with the documents under the documentsId array automatically added.
I wanna thank #samthecodingman for helping me spot the area i need to edit. And #DougStevenson too.
i am new android beginner and try to deploy firebase functions but show some error how to solve this problem plz help me.
Firebase database structure
User Table
Users
user_id
device_token : user_device_token
Name : user_name
Notification Table
notifications
to_user_id
notification_id
from : from_user_id
Error
Index.js
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
/*
* 'OnWrite' works as 'addValueEventListener' for android. It will fire the function
* everytime there is some item added, removed or changed from the provided 'database.ref'
* 'sendNotification' is the name of the function, which can be changed according to
* your requirement
*/
exports.sendNotification = functions.database.ref('/notifications/{user_id}/{notification_id}').onWrite(event => {
/*
* You can store values as variables from the 'database.ref'
* Just like here, I've done for 'user_id' and 'notification'
*/
const user_id = event.params.user_id;
const notification_id = event.params.notification_id;
console.log('We have a notification from : ', user_id);
/*
* Stops proceeding to the rest of the function if the entry is deleted from database.
* If you want to work with what should happen when an entry is deleted, you can replace the
* line from "return console.log.... "
*/
if(!event.data.val()){
return console.log('A Notification has been deleted from the database : ', notification_id);
}
/*
* 'fromUser' query retreives the ID of the user who sent the notification
*/
const fromUser = admin.database().ref(`/notifications/${user_id}/${notification_id}`).once('value');
return fromUser.then(fromUserResult => {
const from_user_id = fromUserResult.val().from;
console.log('You have new notification from : ', from_user_id);
/*
* The we run two queries at a time using Firebase 'Promise'.
* One to get the name of the user who sent the notification
* another one to get the devicetoken to the device we want to send notification to
*/
const userQuery = admin.database().ref(`/Users/${from_user_id}/Name`).once('value');
const deviceToken = admin.database().ref(`/Users/${user_id}/device_token`).once('value');
return Promise.all([userQuery, deviceToken]).then(result => {
const userName = result[0].val();
const token_id = result[1].val();
/*
* We are creating a 'payload' to create a notification to be sent.
*/
const payload = {
notification: {
title : "New Friend Request",
body: `${userName} has sent you request`,
icon: "default",
}
};
/*
* Then using admin.messaging() we are sending the payload notification to the token_id of
* the device we retreived.
*/
return admin.messaging().sendToDevice(token_id, payload).then(response => {
console.log('This was the notification Feature');
});
});
});
});
**cmd show error **
C:\Users\TahirAliAwan\Desktop\Function>firebase deploy
=== Deploying to 'videochat-96f75'...
i deploying functions
Running command: npm --prefix %RESOURCE_DIR% run lint
functions# lint C:\Users\TahirAliAwan\Desktop\Function\functions
eslint .
C:\Users\TahirAliAwan\Desktop\Function\functions\index.js
61:11 warning Avoid nesting promises promise/no-nesting
84:14 warning Avoid nesting promises promise/no-nesting
84:69 error Each then() should return a value or throw promise/always-return
✖ 3 problems (1 error, 2 warnings)
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "--prefix" "C:\Users\TahirAliAwan\Desktop\Function\functions" "run" "lint"
npm ERR! node v6.11.5
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! functions# lint: eslint .
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions# lint script 'eslint .'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the functions package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! eslint .
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs functions
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls functions
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\TahirAliAwan\Desktop\Function\npm-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code1
After #PeterHaddad tip and my effort, I solved this problem by removing this line
.then(response => { console.log('This was the notification Feature'); and update nodejs.
Thanks to all.
Here's my interactive session. It works great.
ec2-54-83-60-31.compute-1.amazonaws.com:11729> keys *
1) testkey
ec2-54-83-60-31.compute-1.amazonaws.com:11729> flushall
OK
ec2-54-83-60-31.compute-1.amazonaws.com:11729> keys *
ec2-54-83-60-31.compute-1.amazonaws.com:11729> watch testkey
OK
ec2-54-83-60-31.compute-1.amazonaws.com:11729> multi
OK
ec2-54-83-60-31.compute-1.amazonaws.com:11729> set testkey testvalue
QUEUED
ec2-54-83-60-31.compute-1.amazonaws.com:11729> exec
1) OK
ec2-54-83-60-31.compute-1.amazonaws.com:11729> keys *
1) testkey
ec2-54-83-60-31.compute-1.amazonaws.com:11729> get testkey
testvalue
ec2-54-83-60-31.compute-1.amazonaws.com:11729>
Here's the my code, and how executing it looks.
var redis = require('redis');
var rdsclt = redis.createClient(process.env.REDIS_URL);
console.log('Before test block.');
console.log('rdsclt.flushall();');
rdsclt.flushall();
console.log('rdsclt.watch(\'testkey\');');
rdsclt.watch('testkey');
console.log('rdsclt.multi();');
rdsclt.multi();
console.log('rdsclt.set(\'testkey\', \'testvalue\');');
rdsclt.set('testkey', 'testvalue');
console.log('rdsclt.exec( (error, results) => {');
rdsclt.exec( (error, results) => {
console.log('Inside test block exec callback.');
console.log('error =', JSON.stringify(error) );
console.log('results =', JSON.stringify(results) );
});
console.log('After test block.');
return 0; // Hopefully, indicates success, in Unix.
2016-11-07T19:39:20.038712+00:00 heroku[web.1]: Starting process with command `npm start`
2016-11-07T19:39:22.685896+00:00 app[web.1]:
2016-11-07T19:39:22.685912+00:00 app[web.1]: > cubsredistest#1.0.0 start /app
2016-11-07T19:39:22.685913+00:00 app[web.1]: > node main.js
2016-11-07T19:39:22.685914+00:00 app[web.1]:
2016-11-07T19:39:22.918869+00:00 app[web.1]: Before test block.
2016-11-07T19:39:22.919519+00:00 app[web.1]: rdsclt.flushall();
2016-11-07T19:39:22.920435+00:00 app[web.1]: rdsclt.watch('testkey');
2016-11-07T19:39:22.920662+00:00 app[web.1]: rdsclt.multi();
2016-11-07T19:39:22.920903+00:00 app[web.1]: rdsclt.set('testkey', 'testvalue');
2016-11-07T19:39:22.920959+00:00 app[web.1]: rdsclt.exec( (error, results) => {
2016-11-07T19:39:22.921021+00:00 app[web.1]: After test block.
2016-11-07T19:39:22.937915+00:00 app[web.1]: Inside test block exec callback.
2016-11-07T19:39:22.938011+00:00 app[web.1]: error = {"command":"EXEC","code":"ERR"}
2016-11-07T19:39:22.938287+00:00 app[web.1]: results = undefined
2016-11-07T19:39:00+00:00 app[heroku-redis]: source=REDIS sample#active-connections=1 sample#load-avg-1m=0.09 sample#load-avg-5m=0.13 sample#load-avg-15m=0.1 sample#read-iops=0 sample#write-iops=0 sample#memory-total=15664468.0kB sample#memory-free=13536884.0kB sample#memory-cached=694560kB sample#memory-redis=289016bytes sample#hit-rate=1 sample#evicted-keys=0
I would have said these two should yield the same results, and yet they don't. I'm using the redis client that is installed using npm install redis . I know there are other clients.
Does anybody know what's going on?
I changed the node client from node_redis to ioredis.
Changed from npm install redis to npm install ioredis.
Now the error message is more informative.
2016-11-07T20:28:02.704282+00:00 app[web.1]: Inside test block exec callback.
2016-11-07T20:28:02.704615+00:00 app[web.1]: error = {"name":"ReplyError","message":"ERR EXEC without MULTI","command":{"name":"exec","args":[]}}
2016-11-07T20:28:02.704620+00:00 app[web.1]: results = undefined
2016-11-07T20:27:43+00:00 app[heroku-redis]: source=REDIS sample#active-connecti
Still haven't solved the problem.
Arghh! An example from node_redis' tests is:
it('does not execute transaction if watched key was modified prior to execution', function (done) {
client.WATCH(watched);
client.incr(watched);
var multi = client.multi();
multi.incr(watched);
multi.exec(helper.isNull(done));
});
What I was doing is this:
it('does not execute transaction if watched key was modified prior to execution', function (done) {
client.WATCH(watched);
client.incr(watched);
client.multi();
client.incr(watched);
client.exec(helper.isNull(done));
});
I'll leave this here. Maybe it'll help the next person.
I'm attempting to run the following Gulp task to compile Sass files, using the plugin, gulp-compass on OS X Yosemite 10.5.5.
var path = require("path");
var gulp = require("gulp");
var compass = require("gulp-compass");
gulp.task("compile2013Base", function() {
var projectPath = path.join(__dirname, '../../ ');
gulp.src(['../sass/desktop/css/2013/*.scss']).pipe(compass({
project: projectPath,
css: 'htdocs/assets/css/2013/',
sass: 'sass/desktop/css/2013'
})).on('error', errorHandler).pipe(gulp.dest('../../htdocs/assets/css/2013/'));
});
function errorHandler (error) {
console.log(error.toString());
this.emit('end');
}
However, when I try to run the task like gulp compile2013Base, I get the following error:
> gulp compile2013Base
[13:39:06] Using gulpfile [**redacted**]/scripts/js/gulpfile.js
[13:39:06] Starting 'compile2013Base'...
[13:39:06] Finished 'compile2013Base' after 9.07 ms
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn /usr/bin/compass ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
I already have compass installed at /usr/bin/compass, and running compass in the terminal does not show any errors.
I'm not sure what to go on here, how do I get the error details?
This is helped me
sudo gem install -n /usr/local/bin compass
see Error: "compass:dist" Fatal error: spawn /usr/bin/compass ENOENT
I am calling a sync call using require('fs'); in nodejs
var folder_path = '/home/abc';
var myfiles = ['a.png','b.png'];
_.each(myfiles, function(name){
var data = fs.readFileSync(folder_path+'/'+name);
if(data){
// Some operation
}
});
while calling that function i'm getting Error: EISDIR, illegal operation on a directory
fs.js:488
var r = binding.read(fd, buffer, offset, length, position);
^
Error: EISDIR, illegal operation on a directory
at Object.fs.readSync (fs.js:488:19)
at Object.fs.readFileSync (fs.js:322:28)
at /home/coader/dev/api/controllers/MyController.js:66:30
at Function.forEach ( /home/coader/dev/node_modules/sails/node_modules/lodash/dist/lodash.js:3298:15)
at /home/coader/dev/api/controllers/MyController.js:41:11
at Object.oncomplete (fs.js:108:15)
error: Forever detected script exited with code: 8
Details
$ node -v
v0.10.37
$ nodejs -v
v0.10.37
$ npm -v
1.4.28
Any answer will be appreciable.
Thanks
I think you might have to settle for "myfiles.forEach(function(name)"
var folder_path = '/home/abc';
var myfiles = ['a.png','b.png'];
myfiles.forEach(function(name){
var data = fs.readFileSync(folder_path+'/'+name);
if(data){
// Some operation
}
});