Title: Crash when no terminal width Post by: sciurius on December 13, 2019, 07:43:15 AM If MMA is run in an environment that is not associated with a terminal, it crashes with a weird error.
For example, when using Emacs, edit t.mma and then M-x compile RET mma -n t.mma RET . Code: Traceback (most recent call last): It took me some time to find the cause of the problem. In "common.py", lines 46-47 Code: from MMA.termsize import getTerminalSize Apparently this can fail and will set termwidth to -1, causing the pretty printing to crash. Even though this is a weird case, I'd suggest to add a safety net, e.g. Code: # having the term width is nice for pretty print error/warning Title: Re: Crash when no terminal width Post by: bvdp on December 13, 2019, 04:36:59 PM I have no idea why the termsize.py code is failing, but I suspect that emacs isn't passing it's underlying size ... but, in that case termsize should default to 80x24. It's not that important ... so I'm taking your (easy!) fix. But, rather than <1 should we, perhaps, use <32 or something and default to 80 in that case? I don't want the wrap() function to create other problems. So, I'm suggesting:
if termwidth < 32: termwidth = 32 Thoughts? Title: Re: Crash when no terminal width Post by: sciurius on December 14, 2019, 02:53:13 PM I think best is to stick to two cases.
If termwidth is set, apparently the user or the system wants it so, so try prettyprinting with the given width. If termwidth is -1, do not prettyprint. The change is in MMA/common.py: Code: def prettyPrint(msg): Title: Re: Crash when no terminal width Post by: bvdp on December 14, 2019, 04:26:44 PM Yes, I agree. Patch applied.
Title: Re: Crash when no terminal width Post by: sciurius on December 14, 2019, 05:08:00 PM Thanks!
|