I have a stay-open app that runs for only a few minutes then crashes with a SIGSEGV/Segmentation fault (11).
How do I isolate the offending code, navigate the traceback dump or debug this exception?
I saved the dumps so can supply if needed.
I have a stay-open app that runs for only a few minutes then crashes with a SIGSEGV/Segmentation fault (11).
How do I isolate the offending code, navigate the traceback dump or debug this exception?
I saved the dumps so can supply if needed.
How about supplying the script instead/also…
This following AppleScript code is a basic debugging/error logging template which I created that has helped me isolate errors and problems in my code hundreds and hundreds of times. Basically, it logs the errors, line numbers, time and date, and the name of the file which created the error to a file on your desktop “Script Error Log.log” .
The debugging/error logging function can be disabled simply by setting set debugMode to false
set myName to name of (info for (path to me))
set debugMode to true
try
if debugMode = true then set scriptLocation to currentLineNumber(5) -- Insert Correct Line Numbers
-- place all of your code in this section only
-- set any variables or properties before line 1 at the top of this script
-- add any handlers to the handlers section below
-- add this following line of code directly before any commands that you want logged in the event of an error.
---- if debugMode = true then set scriptLocation to currentLineNumber(12) <---- Insert Correct Line Numbers
if debugMode = true then set scriptLocation to currentLineNumber(15)
on error the errorMessage number the errorNumber
if debugMode = true then errorRoutine(errorMessage, errorNumber, scriptLocation)
end try
-------------- Handlers ---------------
on currentLineNumber(lineNumber)
set scriptLocation to lineNumber
end currentLineNumber
on writeErrorLog(thisError)
set the errorLog to ((path to desktop) as text) & "Script Error Log.log"
do shell script "echo " & "----\\> " & quoted form of thisError & ¬
" >> " & quoted form of POSIX path of errorLog
end writeErrorLog
on errorRoutine(errorMessage, errorNumber, scriptLocation)
set {theDate, myName} to {current date, name of (info for (path to me))}
set the errorText to "Error: " & the errorNumber & ". " & the errorMessage & ¬
" The script error was after LINE:" & scriptLocation & " ... " & ¬
myName & " triggered this error on " & theDate & linefeed
my writeErrorLog(the errorText)
display notification "Check Your Script Error Log File" with title ¬
"SCRIPT ERROR" subtitle (myName & " Triggered An Error")
end errorRoutine
Here is a version using the template code from above you can try out for testing purposes. To generate and log an error, make sure there are no files selected on your desktop or in the finder. Then run this following code…
set myName to name of (info for (path to me))
set destinationFolder to ((path to desktop) as text) & "Test:"
set debugMode to true
try
if debugMode = true then set scriptLocation to currentLineNumber(6) -- Insert Correct Line Numbers
tell application "Finder"
if debugMode = true then set scriptLocation to my currentLineNumber(9) -- Insert Correct Line Numbers
set selectedFile to (item 1 of (get selection)) as alias
if debugMode = true then set scriptLocation to my currentLineNumber(11) -- Insert Correct Line Numbers
set {selectedName, nameExtension} to ({name, name extension} of selectedFile)
end tell
if debugMode = true then set scriptLocation to my currentLineNumber(15) -- Insert Correct Line Numbers
do shell script "cp " & quoted form of POSIX path of selectedFile & " " & quoted form of POSIX path of destinationFolder
if debugMode = true then set scriptLocation to my currentLineNumber(18) -- Insert Correct Line Numbers
-- more code
if debugMode = true then set scriptLocation to my currentLineNumber(21) -- Insert Correct Line Numbers
-- more code
on error the errorMessage number the errorNumber
if debugMode = true then errorRoutine(errorMessage, errorNumber, scriptLocation)
end try
-------------- Handlers ---------------
on currentLineNumber(lineNumber)
set scriptLocation to lineNumber
end currentLineNumber
on writeErrorLog(thisError)
set the errorLog to ((path to desktop) as text) & "Script Error Log.log"
do shell script "echo " & "----\\> " & quoted form of thisError & ¬
" >> " & quoted form of POSIX path of errorLog
end writeErrorLog
on errorRoutine(errorMessage, errorNumber, scriptLocation)
set {theDate, myName} to {current date, name of (info for (path to me))}
set the errorText to "Error: " & the errorNumber & ". " & the errorMessage & ¬
" The script error was after LINE:" & scriptLocation & " ... " & ¬
myName & " triggered this error on " & theDate & linefeed
my writeErrorLog(the errorText)
display notification "Check Your Script Error Log File" with title ¬
"SCRIPT ERROR" subtitle (myName & " Triggered An Error")
end errorRoutine
To generate a second error for testing purposes, select only 1 file in the finder and run the code again.
Check the file on your desktop “Script Error Log.log”
This is how the error logging looks…
Awesome thank you.
I have a couple of nested repeat loops, which shouldn’t be problems if managed correctly, but nevertheless I have redesigned the logic to make the SQL query smarter and do more of the work instead of nested loops. So far so good and will advise.