Skip to content

Commit

Permalink
Avoid sys.exit(1) in read_file(filepath)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjun-menon committed Aug 6, 2024
1 parent 179a704 commit 5534946
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pypage.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,13 @@ def does_end(self, node):
def __repr__(self):
return 'EndBlockTag.\n'

class PypageSyntaxError(Exception):
class PypageError(Exception):
def __init__(self, description='undefined'):
self.description = description
def __str__(self):
return "Error: " + self.description

class PypageSyntaxError(PypageError):
def __init__(self, description='undefined'):
self.description = description
def __str__(self):
Expand Down Expand Up @@ -832,10 +838,9 @@ def read_file(filepath):
with open(filepath, 'r') as source_file:
return source_file.read()
else:
print("File %s does not exist." % repr(filepath), file=sys.stderr)
sys.exit(1)
raise PypageError("File %s does not exist. CWD: %s" % (repr(filepath), os.getcwd()))

__all__ = ['pypage', 'pypage_version']
__all__ = ['pypage', 'pypage_version', PypageError, PypageSyntaxError]

def main():
import argparse
Expand Down

0 comments on commit 5534946

Please sign in to comment.