SD7 Bug/Crash Report When Passing Item Reference

Running Script Debugger 7 7.0.2 (7A51) on macOS 10.12.6

@alldritt, I submitted the “Crash Reporter” report, but I wanted to post the full script here, with some comments that help identify where the crash occurred.

Also, I have commented out references to Keyboard Maestro Engine, which is not involved in the crash.

Crash Location

Here’s where the crash actually occurred:

on textToNum(pString)
  local numOrText
  
  set numOrText to pString
  try
    ### SD7 CRASH HERE when Item was non-numeric chars ###
    ### But main issues is that I had passes an item ref as the parameter ###
    
    set numOrText to numOrText as number
    
  end try
  return numOrText
end textToNum

Caused by passing a list item reference to a handler that expected a string:

        ### THIS DIRECTLY LEADS TO SD7 CRASH ###
        set contents of oSubItem to my textToNum(oSubItem)
        
        ### THIS FIXED IT:  contents of oSubItem ###
        set contents of oSubItem to my textToNum(contents of oSubItem)

Full Script


set testParams to "first line
\\LIST: a,b,c
LIST: 1,X,3"

### CRASH OCCURS with This data ###
set testParams to "LIST: 1,X,3"

set myList to paragraphs of testParams
my splitItems(myList, ",")

on splitItems(pList, pDelim)
  set oldTID to AppleScript's text item delimiters
  set AppleScript's text item delimiters to pDelim
  
  repeat with oItem in pList
    if (oItem starts with "LIST:") then
      set contents of oItem to (text items of LTrim(text 6 thru -1 of oItem))
      repeat with oSubItem in oItem
        
        ### THIS DIRECTLY LEADS TO SD7 CRASH ###
        set contents of oSubItem to my textToNum(oSubItem)
        
        ### THIS FIXED IT:  contents of oSubItem ###
        ###    set contents of oSubItem to my textToNum(contents of oSubItem)
        
      end repeat
      --else if (my isFoundKME("^\\\\+LIST:", oItem)) then
      --  set contents of oItem to (text 2 thru -1 of oItem)
    end if
  end repeat
  
  set AppleScript's text item delimiters to oldTID
  return -- original List was updated
  
end splitItems


--on isFoundKME(pRegEx, pString)
--  tell application "Keyboard Maestro Engine"
--    set isFound to found in pString for pRegEx with regex
--  end tell
--  
--  return isFound
--  
--end isFoundKME


on LTrim(pString)
  set len to length of pString
  repeat with i from 1 to len
    set iChar to character i of pString
    if (iChar ≠ " " and iChar ≠ tab) then exit repeat
  end repeat
  set trimedStr to text i thru -1 of pString
end LTrim

on textToNum(pString)
  local numOrText
  
  set numOrText to pString
  try
    ### SD7 CRASH HERE when Item was non-numeric chars ###
    ### But main issues is that I had passes an item ref as the parameter ###
    
    set numOrText to numOrText as number
    
  end try
  return numOrText
end textToNum

BTW, if anyone knows a better way to convert a list containing both numeric text and alpha text to numbers (where it can), then I’d much welcome it.
Example list:
{"1", "X", "3.14"}

The script posted here is for purposes of reporting a SD7 crash, not to debug code or optimize code.

Thanks for the bug report. I’m able to reproduce the crash when I step through the handler code.

The crash its self is actually AppleScript going into an infinite recursion loop, but Script Debugger is creating the conditions for this to happen. At this stage, I’m not sure there’s much that can be done without a radical re-thinking of how Script Debugger implements step-wise execution. In the short term, I suggest passing contents of a oSubItem to the textToNum handler, or comment out the local numOrText statement within the textToNum handler, to avoid the problem.

I’ve filed a bug at this end so this does not get lost.

Thanks for the reply, Mark.

That is exactly what I did, and it works fine now.