revig / revigniter

Framework for people who build websites using LiveCode
https://revigniter.com/
Apache License 2.0
28 stars 9 forks source link

Fix problem making the framework to fail finding the default controller #14

Closed WilliamDelRey closed 1 year ago

WilliamDelRey commented 1 year ago

Description of the Change or Addition

Possible Side-Effects

-

Verification

WilliamDelRey commented 1 year ago

1 - it occurred with the default 'welcome' controller right after installing revigniter 2- default config, I didn't change anything, I just installed it and had the error

the controller was failing to load because '_rigSetRequest' command was failing to exit on line 320

if (the number of lines in the keys of tSegmentsArray) = 0 then
        exit _rigSetRequest
    end if

since tSegmentsArray was populated by _rigValidateRequest on line 317, when the condition on line 319 happened the tSegmentsArray variable had 1 empty key, so the condition evaluated to false, 'exit _rigSetRequest' never happened and the gRigA["controller"] key was emptied on line 325 by 'rigSetController tSegmentsArray[1]' since tSegmentsArray[1] was empty

WilliamDelRey commented 1 year ago

I haven't worked with revIgniter too much, I was just running some experiments and after installing it on my local server (root htdoc) directory got the error and tracked it down to that section, I'll keep in touch since I will continue to work with revIgniter in my free time for a personal project, I love codeIgniter and I love LC so this is heaven to me :)

revig commented 1 year ago

I really want to figure out in detail what is going on here. Calling the default controller in a fresh installation should never run the lines of code you had an issue with. Could you please do me a favor and set the error logging threshold in application/config/config.lc to 2 (make sure that the application/logs folder is writable)? Then add the following line right after the variables declaration in _rigValidateRequest:

rigLogMessage "debug", "----controller path----" && gRigA["APPPATH"] & "controllers/" & pSegmentsArray[1] & gRigA["EXT"]

Please let me know what's in the debug message (after calling the default controller, of course).

WilliamDelRey commented 1 year ago

it didn't work to the log folder, so I wrote it out to the screen, the result was: ----controller path---- D:/tools/UCBWebServer/root/application/controllers/.lc

WilliamDelRey commented 1 year ago

image

WilliamDelRey commented 1 year ago

if worth of something this is the complete content of gRigA variable (converted to json): {"BASEPATH": "D:/tools/UCBWebServer/root/system/","SELF": "index.lc","systemFolder": "D:/tools/UCBWebServer/root/system","pathTranslated": "D:/tools/UCBWebServer/root/index.lc","applicationFolder": "application","EXT": ".lc","FCPATH": "D:/tools/UCBWebServer/root/index.lc","APPPATH": "D:/tools/UCBWebServer/root/application/","module": null}

revig commented 1 year ago

Many thanks for the information. The key to solving this problem is the missing of the controller name in the result of your test. This means that the pSegmentsArray parameter in function _rigValidateRequest must be empty. So, currently I am investigating why this parameter is empty in your case. Let's go deeper: The _rigValidateRequest function is called by command _rigSetRequest and the pSegmentsArray parameter of this command must be empty too. It is called by command _rigSetRouting. "_rigSetRequest" appears in this command twice, between line 225 and line 238.

Line 225 to 238 in _rigSetRouting reads:

  if sRouterA["defaultController"] contains "/" then
      put sRouterA["defaultController"] into tX
      put item -1 of tX into tController
      rigSetController tController
      rigSetHandler tModule & "Index"
      split tX by "/"
      _rigSetRequest tX
  else
      rigSetController sRouterA["defaultController"]
      rigSetHandler tModule & "Index"
      put sRouterA["defaultController"] into tTempArray[1]
      put tModule & "Index" into tTempArray[2]
      _rigSetRequest tTempArray
  end if

When I look at that, I think the only reason the parameter of _rigSetRequest could be empty is if sRouterA["defaultController"] on line 225 is "/", otherwise the parameter must be an array no matter what its contents are. What do you think? Could you please check the value of sRouterA["defaultController"] right before line 225?

WilliamDelRey commented 1 year ago

I see now that my last comment failed to post for some reason, sorry about that, right before line 255 the value of sRouterA["defaultController"] is "welcome"

revig commented 1 year ago

If in line 224 the value of sRouterA["defaultController"] is "welcome" as you specified, then the condition in line 225 evaluates to false.

This means that the array tTempArray is filled with the value of sRouterA["defaultController"] ("welcome" in this case) and the name of the controller handler ("Index").

Now the command _rigSetRequest is called with a valid array as parameter. This array is then passed to _rigValidateRequest().

In _rigValidateRequest() the value of pSegmentsArray[1] still is "welcome" and the value of pSegmentsArray[2] is "Index".

Then the condition on line 417 evaluates to true, the array is passed back to _rigSetRequest and the function is terminated before the line in question (put "" into tTemp[1]) is reached.

In _rigSetRequest the condition on line 319 evaluates to false and the controller is set to the value of tSegmentsArray[1], which is "welcome".

So, I am a bit puzzled now. Provided you agree that my explanations are correct, how can the value of pSegmentsArray[1] (the controller name) be empty like you reported by citing the log message (----controller path---- D:/tools/UCBWebServer/root/application/controllers/.lc), even though sRouterA["defaultController"] in line 224 is "welcome"? If you disagree with me, where is my fallacy?

WilliamDelRey commented 1 year ago

I think the problem is this: on line 468 the function _rigValidateRequest returns tTemp variable with tTemp being populated by line 467 as: put "" into tTemp[1] then on line 317 you use the _rigValidateRequest() function to populate tSegmentsArray, then on line 319 you use an if to check if the number of keys in tSegmentsArray is 0, here is the problem, the keys is not 0, it was populated by: put "" into tTemp[1] look at line 319, the number of keys of tTemp is 1, not 0 as the number of keys is not 0 execution continues to line 325 by calling: rigSetController tSegmentsArray[1] that's the one setting the ontroller to empty the execution of this handler should end with line 320 (exit _rigSetRequest)

revig commented 1 year ago

All understood and correct provided, and that's the point, that the code in line 467 and 468 is actually executed.

So, the question still stands. You reported, that in line 224 the value of sRouterA["defaultController"] you checked is "welcome", correct?

If you follow this further, like I explained, you will find that the value of the parameter pSegmentsArray[1] of function _rigValidateRequest() is "welcome", and not empty.

But if the value is "welcome", the path to the controller in line 417 should read D:/tools/UCBWebServer/root/application/controllers/welcome.lc, and not D:/tools/UCBWebServer/root/application/controllers/.lc like you reported.

Then the condition in line 417 checks if the path to the controller is valid. Provided the path is valid it evaluates to true, the array including the value "welcome" in pSegmentsArray[1] is returned, and the execution of _rigValidateRequest() is terminated, so that the lines of code (467 and 468), you refer to, are never executed.

So, what I like to understand is if you think that lines 467 and 468 are executed (particularly in a fresh installation), how can this be if the value of sRouterA["defaultController"] ("welcom") is passed through to _rigValidateRequest()?

Is it possible that D:/tools/UCBWebServer/root/application/controllers/welcome.lc is not a valid file path?

revig commented 1 year ago

I hope you don't mind, but I closed the pull request without merging because:

Thanks very much again.

WilliamDelRey commented 1 year ago

No problem Ralf, thank you, great work. I haven't been able to come back to my project, maybe I will these days