Added error handling for editor.
This commit is contained in:
@@ -10,7 +10,7 @@ import praw.errors
|
|||||||
from six.moves import configparser
|
from six.moves import configparser
|
||||||
|
|
||||||
from . import config
|
from . import config
|
||||||
from .exceptions import SubmissionError, SubredditError
|
from .exceptions import SubmissionError, SubredditError, ProgramError
|
||||||
from .curses_helpers import curses_session
|
from .curses_helpers import curses_session
|
||||||
from .submission import SubmissionPage
|
from .submission import SubmissionPage
|
||||||
from .subreddit import SubredditPage
|
from .subreddit import SubredditPage
|
||||||
@@ -99,6 +99,9 @@ def main():
|
|||||||
print('Could not reach submission URL: {}'.format(e.url))
|
print('Could not reach submission URL: {}'.format(e.url))
|
||||||
except SubredditError as e:
|
except SubredditError as e:
|
||||||
print('Could not reach subreddit: {}'.format(e.name))
|
print('Could not reach subreddit: {}'.format(e.name))
|
||||||
|
except ProgramError as e:
|
||||||
|
print('Error: could not open file with program "{}", '
|
||||||
|
'try setting RTV_EDITOR'.format(e.name))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -8,5 +8,10 @@ class SubredditError(Exception):
|
|||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
class ProgramError(Exception):
|
||||||
|
"Problem executing an external program"
|
||||||
|
def __init__(self, name):
|
||||||
|
self.name = name
|
||||||
|
|
||||||
class EscapeInterrupt(Exception):
|
class EscapeInterrupt(Exception):
|
||||||
"Signal that the ESC key has been pressed"
|
"Signal that the ESC key has been pressed"
|
||||||
@@ -6,6 +6,7 @@ from datetime import datetime
|
|||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
|
|
||||||
from . import config
|
from . import config
|
||||||
|
from .exceptions import ProgramError
|
||||||
|
|
||||||
__all__ = ['open_browser', 'clean', 'wrap_text', 'strip_textpad',
|
__all__ = ['open_browser', 'clean', 'wrap_text', 'strip_textpad',
|
||||||
'strip_subreddit_url', 'humanize_timestamp', 'open_editor']
|
'strip_subreddit_url', 'humanize_timestamp', 'open_editor']
|
||||||
@@ -23,7 +24,11 @@ def open_editor(data=''):
|
|||||||
fp.write(data)
|
fp.write(data)
|
||||||
fp.flush()
|
fp.flush()
|
||||||
editor = os.getenv('RTV_EDITOR') or os.getenv('EDITOR') or 'nano'
|
editor = os.getenv('RTV_EDITOR') or os.getenv('EDITOR') or 'nano'
|
||||||
subprocess.Popen([editor, fp.name]).wait()
|
|
||||||
|
try:
|
||||||
|
subprocess.Popen([editor, fp.name]).wait()
|
||||||
|
except OSError as e:
|
||||||
|
raise ProgramError(editor)
|
||||||
|
|
||||||
# Open a second file object to read. This appears to be necessary in
|
# Open a second file object to read. This appears to be necessary in
|
||||||
# order to read the changes made by some editors (gedit). w+ mode does
|
# order to read the changes made by some editors (gedit). w+ mode does
|
||||||
|
|||||||
Reference in New Issue
Block a user