Puzzled by LC 9.6.2 error

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Puzzled by LC 9.6.2 error

Post by jmk_phd » Thu Jul 22, 2021 6:06 am

Thanks Bernard for taking the time to invent and try that test. So it seems there's nothing magical about item 289 that chokes LC 9.x. (Frankly, it would've been truly weird if that had been the case.)

To my mind, the *real* puzzle is that the same stack processes .csv datafiles up to and including LC 8.10 perfectly, yet not in LC 9.x.

I suppose it could be that LC 9.x is more strict and disallows something sloppy that wasn't caught in LC 8.10.

Once I recover from the frustration, I will do a deeper dive by stepping through the code as well as trying out some alternatives.

I'll report back to you and fellow forum members as soon as I know more.

jeff k

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Puzzled by LC 9.6.2 error

Post by Bernard » Thu Jul 22, 2021 6:53 am

Your frustration is understandable.

After I'd gone to bed I realised I should have offered you some more help.

Code: Select all

function doReverseScore pReverseItem
   local tResult
   local tThisResponse
   try
      put item pReverseItem of sScoreList into tThisResponse
   catch tError
      put item pReverseItem-1 of sScoreList
   breakpoint
   end try
   switch
      case tThisResponse is "F"
         put sValuePresent into tResult
      break
   case tThisResponse = "T"
      put sValueAbsent into tResult
      break
   default
      put sValueAbsent into tResult
      break
   end switch
   return tResult
end doReverseScore
The try...catch should enable you to see more of what's going on in the debugger. Check your CSV data around the 289th item. Check your other variables to see they have what you expect. Do your sLocalVars get changed by any other part of your code?

Also perhaps use your LC 8.x IDE to extract the CSV data for us a few lines before 289 and a few lines after. Post that data here, we might see something.

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Puzzled by LC 9.6.2 error

Post by stam » Thu Jul 22, 2021 9:23 am

Try/catch may well find the issue.

In interest of simplifying the remaining code, I would also point out that the switch block is unnecessary. There are only 2 states to assign to tResult and only one condition that sets this to sValuePresent.

Therefore the entire switch block can be replaced with 2 lines:

Code: Select all

put sValueAbsent into tResult
If tThisResponse =“F” then put sValuePresent into tResult

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Puzzled by LC 9.6.2 error

Post by jacque » Thu Jul 22, 2021 5:22 pm

I agree the problem seems to be in the data itself and how LC 9 is processing it, though if it's just a series of letters then I can't think why. And it also doesn't make sense that it only errors on one particular entry.

Edit: if this handler is being called by another handler then the value passed in the parameter is probably wrong. Check what it is exactly (are there extra characters? Something different? Is it really what it should be?) Use the execution contexts button to go back through the calling handler to see if it's passing the parameter properly.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Puzzled by LC 9.6.2 error

Post by jmk_phd » Fri Jul 23, 2021 2:21 am

Thanks so much to everyone -- Bernard, Richmond, Stam, Craig, SparkOut, Jacque -- who have contributed thoughts and suggestions. Over the next few days I will take a very deep dive into the code with all of your comments in mind. I'm truly grateful.

What I simply find so maddening is that the app runs just fine when built as a Win/Mac standalone using LC Indy 8.10, yet breaks when built using LC 9.x from the identical stack, then trying to process the identical .csv datafiles created previously.

I will update here when/if I learn something new. I assume that I need to build the standalone using LC 9.6.2 to ensure that it will run in the most recent versions of macOS and Windows 10.

jeff k

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Puzzled by LC 9.6.2 error

Post by Bernard » Fri Jul 23, 2021 6:28 am

I understand your frustration. It could be that a bug was identified and fixed in LC post 8.10, and it's this fix that has "broken" your app.

The best attitude in this situation is to remind oneself that one will know more about solving problems in code afterwards. Last week I spent a couple of days tracking down why something we've known to be true for 20 years was not true in the case of problem someone was having. So that wasn't even a problem I was having, but something was anomalous and I just had to understand why (because one day it may affect me).

We are all fascinated to know the result of what you find.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Puzzled by LC 9.6.2 error

Post by richmond62 » Fri Jul 23, 2021 10:56 am

I assume that I need to build the standalone using LC 9.6.2 to ensure that it will run in the most recent versions of macOS and Windows 10.
I wonder (this is the standalone builder for LC 8.1.10):
-
Screen Shot 2021-07-23 at 12.51.21 PM.png
-
I shall run off a random stack as a 64-bit standalone 'here' on one of my happy 2006 POlycarbonate Macs running MacOS 10.7.5
and take it home tonight and try it out on my "Monterey Jack" (MacOS 12 beta 3) Mac Mini, and report back. 8)

Let's just hope 'Experimental' doth not mean 'Mental' . . . :lol:

AND . . . come to think of things . . . have you tried any standalones run off from earlier members of the 9.X.X series?

After all, there is quite a slew of versions midst 8.1.10 and 9.6.2.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Puzzled by LC 9.6.2 error

Post by richmond62 » Fri Jul 23, 2021 6:31 pm

OK, I apologise, I went home and built an EXPERIMENTAL 64-bit Mac standalone with
LiveCode 8.2.0 dp2 on MacOS 12 beta 3 rather than what I had intended to do: run one off from
LiveCode 8.1.10 on MacOS 10.7.5 at work.

The standalone built in this way works 100% on MacOS 12 beta 3. 8)

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Puzzled by LC 9.6.2 error

Post by jmk_phd » Fri Jul 23, 2021 10:01 pm

(1) In reply to Bernard and Richmond -- thanks to Bernard's encouragement in writing,
I understand your frustration. It could be that a bug was identified and fixed in LC post 8.10, and it's this fix that has "broken" your app.
Along that line, Richmond speculated (pointing to the change in labeling from "Experimental" for macOS 64-bit between LC 8 and 9):
Have you tried any standalones run off from earlier members of the 9.X.X series?
Actually, I have found that the app breaks in as early as in LC 9.04. I will implement Bernard's try/catch routine.

(2) To Jacque --
I agree the problem seems to be in the data itself and how LC 9 is processing it.
I'm not convinced of the first half of the statement, but definitely agree with the second. Although I've been watching the values of the variables in debugging mode -- which reveal no error in the raw .csv datafile -- I do need to modify the code a bit to copy the custom stack variable into a temp variable so it can be examined along with the others. This may reveal whether your guess is correct.

(3) To Stam -- You wrote,
In interest of simplifying the remaining code, I would also point out that the switch block is unnecessary. There are only 2 states to assign to tResult and only one condition that sets this to sValuePresent.
Ideally that would be true. But the use of switch and a default case was included in order to cope with the (hopefully rare) case that the test respondents -- mostly persons who may not be all that familiar with using a computer -- make a mistake that results in an entry that is neither one of the two expected ("T" or "F") responses. (The code initially prevents the user from entered any other response, but my colleague insisted on including a perilous feature that permits the respondent to go back and change a previous entry, which introduces the possibility of unexpected error.)

Because psychologists use this test for the purpose of clinical diagnosis, I need to include a default so that anything other than "T" or "F" does not count as evidence of psychopathology.

(BTW, the program had to be written as fully bilingual, inasmuch as it will be used mainly in Spanish-speaking countries -- a challenge, insasmuch as I do not speak Spanish. So whatever problem we find with the code, the correction must be made to both the English and Spanish branches of the code.)

jeff k

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Puzzled by LC 9.6.2 error

Post by stam » Sat Jul 24, 2021 12:56 am

jmk_phd wrote:
Fri Jul 23, 2021 10:01 pm
Ideally that would be true. But the use of switch and a default case was included in order to cope with the (hopefully rare) case that the test respondents -- mostly persons who may not be all that familiar with using a computer -- make a mistake that results in an entry that is neither one of the two expected ("T" or "F") responses. (The code initially prevents the user from entered any other response, but my colleague insisted on including a perilous feature that permits the respondent to go back and change a previous entry, which introduces the possibility of unexpected error.)
Hey Jeff,
That's not quite right...You don't need a switch block to cope with unknown responses.
Your switch block says: if "F" then put sValuePresent. If "T" then put sValueAbsent. If something else, then put sValueAbsent.

The only time your switch block puts sValuePresent into tResult is if tThisResponse = "F".

Therefore you can just assign sValueAbsent to tResult blindly (which covers both "T" and 'anything else') and then check if actually this tThisResponse is "F" and change tThisResult to sValuePresent.

The end-result is you convey the same logic in 2 lines as you do in the 11 lines of the switch block.
There are many ways to skin a cat as they say... my preferences is to minimise text (which minimises chance of errors!), but each to his own ;)

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Puzzled by LC 9.6.2 error

Post by jmk_phd » Sat Jul 24, 2021 9:50 pm

Thanks, Stam. Your explanation makes perfect sense now and is indeed more elegant:
You don't need a switch block to cope with unknown responses. <snip> The end-result is you convey the same logic in 2 lines as you do in the 11 lines of the switch block. <snip> my preference is to minimise text (which minimises chance of errors!)
If/when I track down the error causing the app to fail in LC 9.x, I will rewrite that function accordingly. I don't know how much is saved by eliminating the extra lines -- I never cease to be amazed by how fast a thousand-line script runs in LC. But having had no formal training in computer science beyond preparing punchcards for a class project 45 years ago, I welcome learning and adopting best practices in coding.

jeff k

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Puzzled by LC 9.6.2 error

Post by jmk_phd » Tue Aug 03, 2021 1:29 am

Quick update for everyone. (Your help has been much appreciated!) :

No success yet in tracking down the problem when stepping through the code that broke in the LC 9.6.2 IDE and the standalone it generated. I will persist, but I've had to do something in the meantime in order for the app to remain available to visitors wanting to download this from my colleague's website.

Short term, I built Win and Mac standalones (as 64-bit) using LC 8.10 on an older Mac (using the identical stacks), then copied these standalones to a newer Mac running Catalina (and Parallels to test in Windows 10). The not-yet-signed Mac standalone runs fine in Catalina, and a signed Windows .msi installer file downloaded (with the expected "uncommonly downloaded" message) and runs fine in Windows 10 via Parallels.

I've not yet tried the new LC 9.6.3 -- on the chance that something has been fixed -- but I don't have enough information yet to submit a bug report.

I will post another update if/when I learn something more.

jeff k

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Puzzled by LC 9.6.2 error

Post by Bernard » Tue Aug 03, 2021 5:48 am

Here's some other options.

1. Try a CSV validator to see if it catches something strange in your CSV file. https://csvlint.io

2. Try the csvToTab or csvToArray Livecode scripts here. https://github.com/macMikey/csvToText

3. Post your CSV file here (or send it to one of us in private) and see if another pair of eyes can spot the problem.

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Puzzled by LC 9.6.2 error

Post by AxWald » Tue Aug 03, 2021 10:14 am

Hi,

what I do in case of CSV parsing problems:

Version A:
  1. I create a variable before the loop: "put 1 into myVar".
  2. Then I add a line of code at the start of the loop: "put myVar"
  3. When it crashes I see the line number in the CSV where the culprit is hiding.
Version B:
  1. I add a parameter check before the line where the error occurs. By post 3 here I'd do something like:
    ("put item pReverseItem of sScoreList into tThisResponse" crashes, as I understand)

    Code: Select all

       if ((pReverseItem is not a number) OR \    --  first check pReverseItem
             (pReverseItem < 1) OR \
             (pReverseItem > 359)) OR \
             ((sScoreList is empty) OR \          --  then check sScoreList & item
             (pReverseItem < the number of items of sScoreList) OR \
             (pReverseItem > the number of items of sScoreList)) then
          put item pReverseItem of sScoreList into myItem
          breakpoint
       else
          put item pReverseItem of sScoreList into tThisResponse
       end if
  2. Now LC should hit the breakpoint when there's dubious values in the line handled. "myItem" contains the offending item (that causes the error when "put into").
Version C:
  1. At first I change my script so that it loads its CSV from, for instance, SpecialFolderPath("desktop") & "/test.csv".
  2. Then I open both "test.csv" and "original.csv" in my text editor.
  3. Now I paste ~50% of "original.csv" into "test.csv" & save.
  4. If LC processes it w/o error, I delete this part from "original.csv". Else I delete the other half.
  5. Now I go back to 3.
  6. Once I have narrowed my "original.csv" down to a few lines, I step through in the debugger until I have found the culprit.
One of these should find the problem. Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

AndyP
Posts: 614
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Puzzled by LC 9.6.2 error

Post by AndyP » Tue Aug 03, 2021 12:28 pm

Hi Jeff, just catching the end of this thread. It would be really helpful if you could post a link to the raw CSV file that you are loading. This would allow others to test more efficiently. Also we could examine the CSV file to check if there are any other issues, e.g. hidden returns or line ends etc that later versions of Livecode may have less tolerance for.
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”