rzel / python-on-a-chip

Automatically exported from code.google.com/p/python-on-a-chip
Other
0 stars 0 forks source link

do_load() crashes ipm when loading a file with a syntax (or other) error #201

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
ipm> load codewitherror.py
Traceback (most recent call last):
  File "./ipm.py", line 418, in <module>
    main()
  File "./ipm.py", line 383, in main
    i.run()
  File "./ipm.py", line 337, in run
    self.cmdloop()
  File "/usr/lib/python2.6/cmd.py", line 142, in cmdloop
    stop = self.onecmd(line)
  File "./ipm.py", line 269, in onecmd
    cmd.Cmd.onecmd(self, line)
  File "/usr/lib/python2.6/cmd.py", line 219, in onecmd
    return func(arg)
  File "./ipm.py", line 235, in do_load
    code = compile(src, fn, "exec")
  File "codewitherror.py", line 2
    a=1+1
    ^
IndentationError: expected an indented block
~/swbuilds/p14p/src/tools $

The do_load() function should use exceptions like was done for onecmd().

The following implementation for the compile line in do_load() handles the 
problem gracefully:

        src = open(fn).read()

        try:
            code = compile(src, fn, "exec")
        except Exception, e:
            self.stdout.write("%s:%s\n" % (e.__class__.__name__, e))
            return

        img = self.pic.co_to_str(code)

Original issue reported on code.google.com by j...@houseoftechnology.org on 6 May 2011 at 3:49

GoogleCodeExporter commented 9 years ago
JT, another great suggestion and very reasonable fix; thank you.

I made changes as suggested.  Tested on ipm.  Make check passes.

Original comment by dwhall...@gmail.com on 9 May 2011 at 7:24

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 3513118c1d02.

Original comment by dwhall...@gmail.com on 9 May 2011 at 7:25

GoogleCodeExporter commented 9 years ago

Original comment by dwhall...@gmail.com on 15 May 2011 at 8:15