Unable to determine function entry point - azure

Been using MS botframework for a couple months. Developing with the emulator in node and using continuous integration to push to Azure.
Pushed last Wednesday and tested with no problems. Made two very inconsequential code changes and pushed on Friday and no I'm getting:
Exception while executing function: Functions.messages. mscorlib: Unable to determine function entry point. I tried redeploying the older version, same thing.
Thoughts?

The function entrypoint is determined based on this logic. As you can see, the flow is:
If an explicit entry point is defined in function.json, use that
Otherwise; if there's a single exported function, use that
Otherwise; try to use a function named run or index (in that order)
I suspect you were in branch #2, and your minor change introduced new functions, so the runtime is now attempting to locate a function named run or index and that doesn't exist.
Can you please make sure your primary entry point function is named run or index and try again?

Turns out there was a short-lived bug in the Azure git integration and I deployed during the window this bug was live. It modified function.json and left it in an invalid state. Kudos to MS Support for staying with the issue and determining the root cause.

In my case, the root cause is having 1 named export & 1 default export.
To fix this, only export default 1 thing in the entrypoint file (index.js in my case)
Leaving here as a trail in case someone faces the same thing

1) Try stopping the service in Azure:
2) Then go to Kudu: https://[YourAzureSiteName].scm.azurewebsites.net/DebugConsole
and run npm install:
3) Then restart the service in Azure

You can use module.exports for example:
module.exports = async function queryDatabase() {
const pg = require('pg');
//...
//...
}

if you are exporting multiple functions
for example function1, function2 then
by adding this line to the end of file we can resolve this issue.
exports.index = function1

Related

Can't see errors in own node module

I am relatively new to node (moving from PHP) and am encountering a problem that took me a while to figure out (meaning it took me a while to figure out what the problem was and now I have no idea how to fix it).
At the top of my node app (server.js), I have some requires. One of this requires my homemade api like this:
const express = require('express');
const app = express();
const v1 = require('./app/v1.js');
The v1 is just a function that returns the output to the api. However, there are many code problems with the v1 api as I have just wrote it and am testing it for the first time.
However, whenever there is a problem with the v1 function, node doesn't print it out and stop the program like it would if the problem were in the main server.js file. In fact (I am using nodemon so I don't have to restart each time), node just continues running like everything is moving perfectly smoothly. I understand why node would want to do this (they want people's app's to not be dependent on the quality of code of the module). However, this is not helpful for me as I have no idea where my problem is in the v1 module.
Does anyone know how to turn on errors/exceptions for modules? Any help appreciated.
Sounds like its doing its job just fine. Are you sure your v1 is returning the right value? or printing out the value that v1 is returning in server.js? because its not going to automatically print out the returned value, you still have to put it in a console.log(v1()); or something similar. without knowing what v1 actually returns, its hard to say what is suppose to be printed.

How to use `index.js` in a Node.js when creating an Express service?

Hi I am structuring my Node.js project based on this, like so:
Root
product name
index.js: (contains requires for the product and the main export)
productName.js: contains application logic
test
test1.js
test2.js
...
Now I have two questions
What should logically go in index.js? At the moment I have this (would this be a good way to do things and what else might I include in index.js?):
// index.js
var myServer = require('./myServer.js'); // "product name" = "myServer"
module.exports = {
run: myServer.listen
}
Does it matter what I call the object key in module.exports (currently "run")? Why does the server always run when I execute index.js with $ node index.js how does it automatically know to run myServer.listen?
P.S.: I am aware of web structure auto-generation tools, I just wish to understand the logical reason for this suggested structure (the idea of not having any logic in index.js)
As you mentioned this is a Express service, if it is only handling backend of some application or more specifically this is only backend application, I would suggest you change name of your index.js to server.js(Thus explicitly stating that it'll process all service requests).
But if not then even index.js is fine.
Now for
1
What you've put is absolutely fine, apart from this you could require all modules, routes(or controllers whatever you name them) in a way that it serves as entry point to your application. Try not to put any logic in here.
2
Actually the server runs because it executes the script in the file called index.js, the script says myServer.listen, now if you had written console.log("Hello World") and used $ node index.js it would've printed Hello World instead.
Node just expects and executes script that is there in index.js, in your case it is to start the server.
About the logic that why not put anything else in index.js, for me the reasoning I consider good enough is it provides abstraction as it is the entry point I don't want index.js to worry about things like what to do with this data and all. I believe it should provide a base to setup server. Thus following single responsibility to some extent. Also I won't have to touch it ever in projects lifetime unless some major change occurs e.g. I decide to shift from express to something else.
EDIT
Why have a key called run
You seem to have answered it yourself(in comments), you are giving or more proper description would be you're attaching an object to module.exports as it is a object similar to JSON it was supposed to have a key(which could be anything not necessarily run it could've been hii). Now if you don't want to pass a key and export only one thing that is server.listen then you could write same as module.exports = myServer.listen; instead of
module.exports = {
hii: myServer.listen
}
Note that you could export more modules using the way you did. For more details about module.exports refer this or better google about it as this link might expire anytime and does not seem an ideal thing to put on SO.

React FacebookAuth Error: FB.login() called before FB.init()

I'm using the admin-on-rest npm package starter project and trying to plug in a simple SSO Facebook login button using the FacebookAuth npm package. Every time I try to click the "Login" button, I get the following error:
FB.login() called before FB.init()
I'm using an .env file with the following variable: REACT_APP_FACEBOOK_APP_ID and setting it to the right value. I even did console.log() within my app and can see it output.
I checked and I'm only loading the FB SDK once, not multiple times (this was a common issue reported on other threads).
Ok, it turned out to be something pretty dumb, but something to point out nonetheless!
In my .env file, I had accidentally placed a semicolon (;) at the end of the declaration, like this:
REACT_APP_FACEBOOK_APP_ID = XXXXXXXXXXXX;
Apparently .env files do NOT like semi-colons. This was just very difficult to figure out from the error above.
So if any of you want to pull your hair out because of this issue, and you're using similar tech, check to make sure you're syntactically kosher EVERYWHERE variables are being declared.
the funny thing was i forgot to replace your-app-id with my app id:
<script>
FB.init({
appId: 'your-app-id',
autoLogAppEvents: true,
xfbml: true,
version: 'v8.0'
});
</script>

Sail. js / Waterline.js - find() not returning array

Problem: I'm getting unexpected output from code that previously worked.
Code Problem:
sails.models.user.find().then(function (users){...});
is currently returning { id: 1 }
but should return an array of User objects like [{id:x, name:y},...]
Code Alterations:
sails.models.user.find().exec(function (err, users){...}); does not contain an error and returns the same as using .then() like above.
sails.models.user.findOne(1).then(function (users){...}); correctly returns a User like {id:x, name:y}.
sails.models.venue.find().then(function (venues){...}); returns an array of venues, just as substituting any other class besides User.
Note:
This code was previously working (it's a pretty simple line), and the only changes I made between it working and not working was running npm install (but it was previously working on heroku where which installed, so I don't think that was a problem) and changing the schema of User to add a few columns (I did this by deleting the User table in the DB, updating the Sails User model, and lifting the app in create mode, so the table exactly matches the model). Neither of these should cause a problem, but we all know how "should" and coding don't mix :P
How do I fix this? And why did this happen? Thanks :)
Realized other code was calling the package sails-mock-models which was doing its job. Totally forgot about that code. Problem solved.

Netsuite: ReferenceError functionName is not defined

This is probably a stupid one but I have tried all the things I can think of. I am currently getting the below error on my client side script when I try and execute it.
Error: ReferenceError acvt_serialNumber_saveRecord is not defined
On the Script record in Netsuite I have set the saveRecord function as follows:
acvt_serialNumber_saveRecord
The code in the file is:
function acvt_serialNumber_saveRecord(){
/**do stuff */
}
I have reuploaded to code to make sure the right version was in NetSuite. I have added one character to both the script fn name and the fn name on the Script record (as a shot in the dark). I have seen in the Javascript console at runtime that the correct code is in there and I can see the exact function name (I did a ctrl+f for the "undefined" function in the code in the console to make sure spelling was all the same).
NOTHING has worked. I had this code working earlier, but the changes I made were not to this function at all.
Any help is appreciated
Another thing to check is the code that you recently changed. In particular, check for a hanging comma. IE:
var someObj = {
someProp:'somevalue',
};
The comma at the end of 'somevalue' will cause the script to fail, throwing 'undefined' errors.
Have you tried deleting the Script record in NetSuite and re-creating it?
Do you have any library included for that Client Script in netsuite ?
Provide a screen shot of your Netsuite script page
I encounter similar problem like this before, but it was because i called a function which is inside a library file
Thanks

Resources