Improved config error reporting.

This commit is contained in:
Michael Lazar
2016-02-10 00:35:51 -08:00
parent d08b9f47be
commit a0da5fc6ca
7 changed files with 24 additions and 26 deletions

View File

@@ -14,6 +14,7 @@ from .oauth import OAuthHelper
from .terminal import Terminal from .terminal import Terminal
from .objects import curses_session from .objects import curses_session
from .subreddit import SubredditPage from .subreddit import SubredditPage
from .exceptions import ConfigError
from .__version__ import __version__ from .__version__ import __version__
@@ -106,6 +107,9 @@ def main():
# Launch the subreddit page # Launch the subreddit page
page.loop() page.loop()
except ConfigError as e:
_logger.exception(e)
print(e)
except Exception as e: except Exception as e:
_logger.exception(e) _logger.exception(e)
raise raise

View File

@@ -6,18 +6,14 @@ class EscapeInterrupt(Exception):
"Signal that the ESC key has been pressed" "Signal that the ESC key has been pressed"
class ConfigError(Exception):
"There was a problem with the configuration"
class RTVError(Exception): class RTVError(Exception):
"Base RTV error class" "Base RTV error class"
class KeystringError(RTVError):
"Unable to parse key string"
class ConfigError(RTVError):
"There was a problem with the configuration"
class AccountError(RTVError): class AccountError(RTVError):
"Could not access user account" "Could not access user account"

View File

@@ -39,7 +39,6 @@ class Page(object):
self.oauth = oauth self.oauth = oauth
self.content = None self.content = None
self.nav = None self.nav = None
self.controller = None
self.active = True self.active = True
self._row = 0 self._row = 0

View File

@@ -55,12 +55,12 @@ oauth_scope = edit,history,identity,mysubreddits,privatemessages,read,report,sav
############## ##############
# Key Bindings # Key Bindings
############## ##############
; Multiple keys that represent the same command should be listed as a comma ; If you would like to define custom bindings, copy this section into your
; seperated list. The a mixture of the following notations should be used to ; config file with the [bindings] heading. All commands must be bound to at
; describe keys. ; least one key for the config to be valid.
; ;
; 1.) Plain keys can be represented by either uppercase/lowercase characters ; 1.) Plain keys can be represented by either uppercase/lowercase characters
; or the hexadecimal codes referring their ascii codes. For reference, see ; or the hexadecimal numbers referring their ascii codes. For reference, see
; https://en.wikipedia.org/wiki/ASCII#ASCII_printable_code_chart ; https://en.wikipedia.org/wiki/ASCII#ASCII_printable_code_chart
; e.g. Q, q, 1, ? ; e.g. Q, q, 1, ?
; e.g. 0x20 (space), 0x3c (less-than sign) ; e.g. 0x20 (space), 0x3c (less-than sign)
@@ -77,9 +77,10 @@ oauth_scope = edit,history,identity,mysubreddits,privatemessages,read,report,sav
; Notes: ; Notes:
; - Curses <KEY_ENTER> is unreliable and should always be used in conjunction ; - Curses <KEY_ENTER> is unreliable and should always be used in conjunction
; with <LF>. ; with <LF>.
; - Use 0x20 for the space key
; General keys ; Base page
EXIT = q EXIT = q
FORCE_EXIT = Q FORCE_EXIT = Q
HELP = ? HELP = ?
SORT_HOT = 1 SORT_HOT = 1
@@ -115,4 +116,4 @@ SUBREDDIT_OPEN_SUBSCRIPTIONS = s
; Subscription page ; Subscription page
SUBSCRIPTION_SELECT = l, <LF>, <KEY_ENTER>, <KEY_RIGHT> SUBSCRIPTION_SELECT = l, <LF>, <KEY_ENTER>, <KEY_RIGHT>
SUBSCRIPTION_EXIT = h, s, <ESC>, <KEY_LEFT> SUBSCRIPTION_EXIT = h, s, <ESC>, <KEY_LEFT>

View File

@@ -17,14 +17,13 @@ class SubmissionController(PageController):
class SubmissionPage(Page): class SubmissionPage(Page):
def __init__(self, reddit, term, config, oauth, url=None, submission=None): def __init__(self, reddit, term, config, oauth, url=None, submission=None):
super(SubmissionPage, self).__init__(reddit, term, config, oauth) self.controller = SubmissionController(self, keymap=config.keymap)
super(SubmissionPage, self).__init__(reddit, term, config, oauth)
if url: if url:
self.content = SubmissionContent.from_url(reddit, url, term.loader) self.content = SubmissionContent.from_url(reddit, url, term.loader)
else: else:
self.content = SubmissionContent(submission, term.loader) self.content = SubmissionContent(submission, term.loader)
self.controller = SubmissionController(self, keymap=config.keymap)
# Start at the submission post, which is indexed as -1 # Start at the submission post, which is indexed as -1
self.nav = Navigator(self.content.get, page_index=-1) self.nav = Navigator(self.content.get, page_index=-1)

View File

@@ -10,7 +10,6 @@ from .page import Page, PageController, logged_in
from .objects import Navigator, Color, Command from .objects import Navigator, Color, Command
from .submission import SubmissionPage from .submission import SubmissionPage
from .subscription import SubscriptionPage from .subscription import SubscriptionPage
from .terminal import Terminal
class SubredditController(PageController): class SubredditController(PageController):
@@ -25,10 +24,10 @@ class SubredditPage(Page):
name (string): Name of subreddit to open name (string): Name of subreddit to open
url (string): Optional submission to load upon start url (string): Optional submission to load upon start
""" """
super(SubredditPage, self).__init__(reddit, term, config, oauth)
self.content = SubredditContent.from_name(reddit, name, term.loader)
self.controller = SubredditController(self, keymap=config.keymap) self.controller = SubredditController(self, keymap=config.keymap)
super(SubredditPage, self).__init__(reddit, term, config, oauth)
self.content = SubredditContent.from_name(reddit, name, term.loader)
self.nav = Navigator(self.content.get) self.nav = Navigator(self.content.get)
@SubredditController.register(Command('REFRESH')) @SubredditController.register(Command('REFRESH'))

View File

@@ -15,10 +15,10 @@ class SubscriptionController(PageController):
class SubscriptionPage(Page): class SubscriptionPage(Page):
def __init__(self, reddit, term, config, oauth): def __init__(self, reddit, term, config, oauth):
super(SubscriptionPage, self).__init__(reddit, term, config, oauth)
self.content = SubscriptionContent.from_user(reddit, term.loader)
self.controller = SubscriptionController(self, keymap=config.keymap) self.controller = SubscriptionController(self, keymap=config.keymap)
super(SubscriptionPage, self).__init__(reddit, term, config, oauth)
self.content = SubscriptionContent.from_user(reddit, term.loader)
self.nav = Navigator(self.content.get) self.nav = Navigator(self.content.get)
self.subreddit_data = None self.subreddit_data = None