python-goto icon indicating copy to clipboard operation
python-goto copied to clipboard

Trying to goto a previous line crashes python.

Open IoIxD opened this issue 7 years ago • 1 comments

main.py:

@with_goto
def run():
    keyDict = {"key1": "", "key1G": "", "key2": "", "key2G": "", "key3": "", "key3G": "", "key4": "", "key4G": "", "key5": "", "key5G": "", "key6": "", "key6G": "", "key7": "", "key7G": "", "key8": "", "key8G": "", "key9": "", "key9G": "", "key10": "", "key10G": "", "key11": "", "key11G": "", "key12": "", "key12G": "", "key13": "", "key13G": "", "key14": "", "key14G": "","key15": "", "key15G": ""}
    validParam = 0
    currentLine = 0
    debug = 0
    result = []
    with open("test.dgm") as fp:
            for i, line in enumerate(fp):
                    label .newLine
                    currentGoto = (int(currentLine) - 1)
                    if(currentGoto == -1):
                            currentGoto = 0
                    if(debug == 1):
                            print("Current Line:")
                            print(currentLine)
                            print("Current Goto:")
                            print(currentGoto)
                    if(i == currentGoto):
                            word_list = line.split()
                            cmd = word_list[0]
                            lineR = re.findall('"([^"]*)"', line)
                            lineRa = format(lineR)
                            lineRa = lineRa.replace("[","", 5)
                            lineRa = lineRa.replace("]","", 5)
                            lineRa = lineRa.replace("'","", 5)
                            try: 
                                    paramNumber = word_list[1]
                            except:
                                    print("")
                            
                            if(cmd == ":debug"):
                                    debug = 1
                                    currentLine += 1
                                    goto .newLine
                            
                            if(cmd == ":py"):
                                    if(debug == 1):
                                            print(":py")
                                    exec(lineRa)
                                    currentLine = lineRa
                                    goto .newLine
                                    
                            if(cmd == ":text"):
                                    if(debug == 1):
                                            print(":text")
                                    try:
                                            if(paramNumber >= "1"):
                                                    param1 = word_list[2]
                                                    param1 = param1.replace(":", " ")
                                                    param1_list = param1.split()
                                                    keyDict["key1"] = param1_list[0]
                                                    keyDict["key1G"] = param1_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "2"):
                                                    param2 = word_list[3]
                                                    param2 = param2.replace(":", " ")
                                                    param2_list = param2.split()
                                                    keyDict["key2"] = param2_list[0]
                                                    keyDict["key2G"] = param2_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "3"):
                                                    param3 = word_list[4]
                                                    param3 = param3.replace(":", " ")
                                                    param3_list = param3.split()
                                                    keyDict["key3"] = param3_list[0]
                                                    keyDict["key3G"] = param3_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "4"):
                                                    param4 = word_list[5]
                                                    param4 = param4.replace(":", " ")
                                                    param4_list = param4.split()
                                                    keyDict["key4"] = param4_list[0]
                                                    keyDict["key4G"] = param4_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "5"):
                                                    param5 = word_list[6]
                                                    param5 = param5.replace(":", " ")
                                                    param5_list = param5.split()
                                                    keyDict["key5"] = param5_list[0]
                                                    keyDict["key5G"] = param5_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "6"):
                                                    param6 = word_list[7]
                                                    param6 = param6.replace(":", " ")
                                                    param6_list = param6.split()
                                                    keyDict["key6"] = param6_list[0]
                                                    keyDict["key6G"] = param6_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "7"):
                                                    param7 = word_list[8]
                                                    param7 = param1.replace(":", " ")
                                                    param7_list = param1.split()
                                                    keyDict["key7"] = param7_list[0]
                                                    keyDict["key7G"] = param7_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "8"):
                                                    param8 = word_list[9]
                                                    param8 = param8.replace(":", " ")
                                                    param8_list = param8.split()
                                                    keyDict["key8"] = param8_list[0]
                                                    keyDict["key8G"] = param8_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "9"):
                                                    param9 = word_list[10]
                                                    param9 = param9.replace(":", " ")
                                                    param9_list = param9.split()
                                                    keyDict["key9"] = param9_list[0]
                                                    keyDict["key9G"] = param9_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "10"):
                                                    param10 = word_list[11]
                                                    param10 = param10.replace(":", " ")
                                                    param10_list = param10.split()
                                                    keyDict["key10"] = param10_list[0]
                                                    keyDict["key10G"] = param10_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "11"):
                                                    param11 = word_list[12]
                                                    param11 = param11.replace(":", " ")
                                                    param11_list = param11.split()
                                                    keyDict["key11"] = param11_list[0]
                                                    keyDict["key11G"] = param11_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "12"):
                                                    param12 = word_list[13]
                                                    param12 = param12.replace(":", " ")
                                                    param12_list = param12.split()
                                                    keyDict["key12"] = param12_list[0]
                                                    keyDict["key12G"] = param12_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "13"):
                                                    param13 = word_list[14]
                                                    param13 = param13.replace(":", " ")
                                                    param13_list = param13.split()
                                                    keyDict["key13"] = param13_list[0]
                                                    keyDict["key13G"] = param13_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "14"):
                                                    param14 = word_list[15]
                                                    param14 = param14.replace(":", " ")
                                                    param14_list = param14.split()
                                                    keyDict["key14"] = param14_list[0]
                                                    keyDict["key14G"] = param14_list[1]
                                                    validParam = 1
                                            if(paramNumber >= "15"):
                                                    param15 = word_list[16]
                                                    param15 = param15.replace(":", " ")
                                                    param15_list = param15.split()
                                                    keyDict["key15"] = param15_list[0]
                                                    keyDict["key15G"] = param15_list[1]
                                                    validParam = 1
                                            if(validParam == 0):
                                                    print("An invalid number of parameters was specified on line "+str(i)+". The minimum amount of parameters you can add is 1; the maximum amount is 15.")
                                                    stop = input("")
                                                    sys.exit()
                                    except IndexError:
                                            print("")
                                    nextInput = input(lineRa)
                                    if(nextInput == ""):
                                            print("You did not enter anything.")
                                            goto .newLine
                                    if(nextInput == keyDict["key1"]):
                                            currentLine = keyDict["key1G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key2"]):
                                            currentLine = keyDict["key2G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key3"]):
                                            currentLine = keyDict["key3G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key4"]):
                                            currentLine = keyDict["key4G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key5"]):
                                            currentLine = keyDict["key5G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key6"]):
                                            currentLine = keyDict["key6G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key7"]):
                                            currentLine = keyDict["key7G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key8"]):
                                            currentLine = keyDict["key8G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key9"]):
                                            currentLine = keyDict["key9G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key10"]):
                                            currentLine = keyDict["key10G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key11"]):
                                            currentLine = keyDict["key11G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key12"]):
                                            currentLine = keyDict["key12G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key13"]):
                                            currentLine = keyDict["key13G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key14"]):
                                            currentLine = keyDict["key14G"]
                                            goto .newLine
                                    if(nextInput == keyDict["key15"]):
                                            currentLine = keyDict["key15G"]
                                            goto .newLine
                            print("Invalid command specified.")
                            goto .newLine

test.dgm:

:text 2 A:2 B:3 "This is line 1."
:text 2 A:3 B:1 "This is line 2."
:text 2 A:1 B:2 "This is line 3."

This works as it should, but when I press the key that takes me to the previous line, the program just stops, with no error.

IoIxD avatar Aug 30 '18 03:08 IoIxD

I'm not a committer, but I've taken a look at this since I'm using this module and don't want it to crash, but:

a) It's really not clear what "the key that takes me to the previous line" is (crucial information missing from bug report). Is it "B"? I'm going to assume it's "B" unless you say otherwise.

b) If I press A<enter>, then B<enter> (or B<enter>, then B<enter>) - the program indeed "just stops, with no errors". More specifically, it exits the function and successfully terminates. It does not crash.

Based on the above two points, I'm assuming this isn't a valid crash report. If it is, and you want it looked at, please clarify the issue and how to reproduce it.

insignification avatar Dec 10 '19 22:12 insignification