Client code crashing; "network" object nil / not found

My client code is crashing in mod_coronium.lua, line 424, at a call to the network.request function, because the network object is nil at that point.  ie. there is no server or http aspect to this failure.

(As an aside, this client-side call to network.request looks to be very similar to the server-side equivalent documented in the HTTP section, ref: http://docs.coronium.io/en/latest/server/HTTP/#networkrequest)

Is there another module that I need to require in order to access this object?

My code is very simple test code that attempts to INSERT a record into a MySQL table.

I am running my client code within the ZeroBrane Studio – which I have used successfully many times – rather than the Sublime Text editor; this is pretty much the only difference I can see from the video example.

Hi,

What version of the client are you running? (current releases will have a version at the top of the mod_coronium file), where are you hosting, and what Coronium server version? Make sure to log in to your admin panel and click the green button to get the latest.

Also, there have been reports – unrelated to Coronium – that ZeroBrane studio can cause issues with networking because of how it debugs. I would at least test with something like Atom or Sublime so you can remove that as one possibility.

Thank you.

Firstly, the version of mod_coronium.lua that I am using is  v1.92.5  which is the most recent, I believe.

And, my server is an AWS EC2 t2.micro instance running Coronium Cloud Platform 1.93.1  but, as previously mentioned, my failing client code was getting nowhere near it.

Secondly, I fixed the fault – I think.  I have no explanation for why my fix works; I will explain…

I ran the failing code within Sublime Text 3 and got the exact same failure for the same reason, so the error was not specific to ZeroBrane.

However, Sublime has superior syntax highlighting – at least as I have the 2 tools configured – as it shows function declarations in green and function calls in blue.

The failing function call (on line 424 ) was being highlighted as a declaration; when I changed the 3rd parameter to network.request() from being a closure this corrected itself (but, of course, stuffed up the code).

I noticed that a previous similar call, to network.upload() (on line 292 ), is correctly highlighted and has all its parameters on subsequent lines.  I moved the parameters of the failing call (line 424 ) to the next line and not only did the highlighting correct itself but the code now ran correctly !  (I now have records on my AWS server instance.)

  local q = {
    requestId = network.request (
      uri, action, function (e) Coronium:onResponse(e); end , requestParams ),
    requestType = requestType,
    _callback = _callback,
  }

I am not a fan of “magic” happening in code; I would be delighted and very grateful if any clever person can explain this fix.

Edit: I forgot to mention that I am developing/running my client on a Windows 10 machine.

I also moved parameters to the next line for the other call to network.request() on line 461.

Additionally, as part of my mucking around, I updated my Corona SDK from 2015.2731 (circa Oct 2015) to the most recent public release (2016.2830).

Chris Bargh

Hi,

I’m taking a look at this now. Seems a bit strange.

Thanks for reporting.

Hi,

I realized that I have not got to see your code implementation yet. Could be helpful.

So I don’t have access to Windows 10 (yet), but everything seems to check out. But, I’ll reserve my judgment until I actually try it on a Win 10 box.

I put together a screencast that runs through the process, I think it’s good to cover this topic.

I’ll hopefully get that 10 box together over the weekend and give it a whirl. You shouldn’t have to be changing code to get it working. As exemplified in the screencast.

Cast: https://www.youtube.com/watch?v=BlolnR-6ngg

Files: https://s3.amazonaws.com/coronium-assets/coronium_mysql.zip

Cheers.

Hi Chris,

My code was just a slight tweek – use of inspect mainly – of that in your “Using MySQL” youtube video…

Client side main.lua

local globals = require (“globals”)    – only contains appId & apiKey

local mc      = require (“mod_coronium”)

local inspect = require (“inspect”)

mc:init( {appId = globals.appId, apiKey = globals.apiKey} )

local function onRun( event )

   print ( inspect( event ) )

end

mc:run( " insert", { username = ‘Charles’ }, onRun )

Server side insert.lua

local in_data  = coronium.input()

local username = coronium.utils.mysqlString( in_data.username )

local q = string.format(“INSERT INTO User (UserName) VALUES (%s)”, username )

local answer = coronium.mysql.query( {database = “users”}, q )

coronium.output( answer )

Edit: I just looked through your zip file; my code follows the same principles.

Cheers

Chris

Hi,

I assume you get the same result if you disable your ‘inspect’ module?

To my embarrassment I broke one of the first rules of fault-finding and did not save my original setup.  To make things worse, after rolling back to what I think I had, I can no longer reproduce the fault.

I have tried with and without ‘inspect’,  with and without my changes to mod_coronium.lua  and  in both Sublime Text 3 and ZeroBrane.

Incidentally, without my change on line 424 of mod_coronium.lua, Sublime still shows the “incorrect” syntax highlighting with the parameters on the same line as the call to network.request() – again fixed if parameters moved to next line (ie. a linefeed added) – but, with or without my “fix”, I am now no longer seeing the “network object nil” error. Indeed, inspection of the network object now shows that it is not nil.

The original problem was not imagined; another independent Lua developer witnessed it and I sat with him for several hours until we stumbled upon the fix/workaround.

I don’t know where to go from here and can only suggest tabling the problem until it resurfaces, if it ever does.

Hi,

What version of the client are you running? (current releases will have a version at the top of the mod_coronium file), where are you hosting, and what Coronium server version? Make sure to log in to your admin panel and click the green button to get the latest.

Also, there have been reports – unrelated to Coronium – that ZeroBrane studio can cause issues with networking because of how it debugs. I would at least test with something like Atom or Sublime so you can remove that as one possibility.

Thank you.

Firstly, the version of mod_coronium.lua that I am using is  v1.92.5  which is the most recent, I believe.

And, my server is an AWS EC2 t2.micro instance running Coronium Cloud Platform 1.93.1  but, as previously mentioned, my failing client code was getting nowhere near it.

Secondly, I fixed the fault – I think.  I have no explanation for why my fix works; I will explain…

I ran the failing code within Sublime Text 3 and got the exact same failure for the same reason, so the error was not specific to ZeroBrane.

However, Sublime has superior syntax highlighting – at least as I have the 2 tools configured – as it shows function declarations in green and function calls in blue.

The failing function call (on line 424 ) was being highlighted as a declaration; when I changed the 3rd parameter to network.request() from being a closure this corrected itself (but, of course, stuffed up the code).

I noticed that a previous similar call, to network.upload() (on line 292 ), is correctly highlighted and has all its parameters on subsequent lines.  I moved the parameters of the failing call (line 424 ) to the next line and not only did the highlighting correct itself but the code now ran correctly !  (I now have records on my AWS server instance.)

  local q = {
    requestId = network.request (
      uri, action, function (e) Coronium:onResponse(e); end , requestParams ),
    requestType = requestType,
    _callback = _callback,
  }

I am not a fan of “magic” happening in code; I would be delighted and very grateful if any clever person can explain this fix.

Edit: I forgot to mention that I am developing/running my client on a Windows 10 machine.

I also moved parameters to the next line for the other call to network.request() on line 461.

Additionally, as part of my mucking around, I updated my Corona SDK from 2015.2731 (circa Oct 2015) to the most recent public release (2016.2830).

Chris Bargh

Hi,

I’m taking a look at this now. Seems a bit strange.

Thanks for reporting.

Hi,

I realized that I have not got to see your code implementation yet. Could be helpful.

So I don’t have access to Windows 10 (yet), but everything seems to check out. But, I’ll reserve my judgment until I actually try it on a Win 10 box.

I put together a screencast that runs through the process, I think it’s good to cover this topic.

I’ll hopefully get that 10 box together over the weekend and give it a whirl. You shouldn’t have to be changing code to get it working. As exemplified in the screencast.

Cast: https://www.youtube.com/watch?v=BlolnR-6ngg

Files: https://s3.amazonaws.com/coronium-assets/coronium_mysql.zip

Cheers.

Hi Chris,

My code was just a slight tweek – use of inspect mainly – of that in your “Using MySQL” youtube video…

Client side main.lua

local globals = require (“globals”)    – only contains appId & apiKey

local mc      = require (“mod_coronium”)

local inspect = require (“inspect”)

mc:init( {appId = globals.appId, apiKey = globals.apiKey} )

local function onRun( event )

   print ( inspect( event ) )

end

mc:run( " insert", { username = ‘Charles’ }, onRun )

Server side insert.lua

local in_data  = coronium.input()

local username = coronium.utils.mysqlString( in_data.username )

local q = string.format(“INSERT INTO User (UserName) VALUES (%s)”, username )

local answer = coronium.mysql.query( {database = “users”}, q )

coronium.output( answer )

Edit: I just looked through your zip file; my code follows the same principles.

Cheers

Chris

Hi,

I assume you get the same result if you disable your ‘inspect’ module?

To my embarrassment I broke one of the first rules of fault-finding and did not save my original setup.  To make things worse, after rolling back to what I think I had, I can no longer reproduce the fault.

I have tried with and without ‘inspect’,  with and without my changes to mod_coronium.lua  and  in both Sublime Text 3 and ZeroBrane.

Incidentally, without my change on line 424 of mod_coronium.lua, Sublime still shows the “incorrect” syntax highlighting with the parameters on the same line as the call to network.request() – again fixed if parameters moved to next line (ie. a linefeed added) – but, with or without my “fix”, I am now no longer seeing the “network object nil” error. Indeed, inspection of the network object now shows that it is not nil.

The original problem was not imagined; another independent Lua developer witnessed it and I sat with him for several hours until we stumbled upon the fix/workaround.

I don’t know where to go from here and can only suggest tabling the problem until it resurfaces, if it ever does.