Rename error handling
- move errors in a `error` module - rename the module base error from `Error` to `ModuleError` - fix some error handling in `__main__`
This commit is contained in:
parent
db0a954497
commit
07ef013ce3
|
@ -14,14 +14,14 @@ import time
|
|||
|
||||
import requests
|
||||
|
||||
from . import api, cli, common, hls, muxing, naming, www
|
||||
from . import api, cli, error, hls, muxing, naming, www
|
||||
|
||||
|
||||
class Abort(common.Error):
|
||||
class Abort(error.ModuleError):
|
||||
"""Aborted."""
|
||||
|
||||
|
||||
class Fail(common.UnexpectedError):
|
||||
class Fail(error.UnexpectedError):
|
||||
"""Unexpected error."""
|
||||
|
||||
|
||||
|
@ -181,29 +181,31 @@ def main():
|
|||
with hls.download_source(http_session, source, progress) as local_source:
|
||||
muxing.mux_source(local_source, file_name, progress)
|
||||
|
||||
except common.UnexpectedError as e:
|
||||
except error.UnexpectedError as e:
|
||||
print(str(e))
|
||||
print()
|
||||
print(
|
||||
"This program is the result of browser/server traffic analysis and involves "
|
||||
"some level of trying and guessing. This error might mean that we did not try "
|
||||
"enough of that we guessed poorly."
|
||||
"This program is the result of browser/server traffic analysis and involves\n"
|
||||
"some level of trying and guessing. This error might mean that we did not try\n"
|
||||
"enough or that we guessed poorly."
|
||||
)
|
||||
print("")
|
||||
print("Please consider submitting the issue to us so we may fix it.")
|
||||
print("")
|
||||
print("Issue tracker: https://git.afpy.org/fcode/delarte/issues")
|
||||
print(f"Title: {e.args(0)}")
|
||||
print(f"Title: {e.args[0]}")
|
||||
print("Body:")
|
||||
print(f" {repr(e)}")
|
||||
return 1
|
||||
|
||||
except common.Error as e:
|
||||
except error.ModuleError as e:
|
||||
print(str(e))
|
||||
print(repr(e))
|
||||
# print(repr(e))
|
||||
return 1
|
||||
|
||||
except requests.HTTPError as e:
|
||||
print("Network error.")
|
||||
print(str(e))
|
||||
# print(str(e))
|
||||
return 1
|
||||
|
||||
|
||||
|
|
|
@ -3,20 +3,20 @@
|
|||
|
||||
"""Provide ArteTV JSON API utilities."""
|
||||
|
||||
from . import common, model
|
||||
from . import error, model
|
||||
|
||||
MIME_TYPE = "application/vnd.api+json; charset=utf-8"
|
||||
|
||||
|
||||
class UnexpectedResponse(common.UnexpectedError):
|
||||
class UnexpectedResponse(error.UnexpectedError):
|
||||
"""Unexpected response from ArteTV."""
|
||||
|
||||
|
||||
class NotFound(common.Error):
|
||||
class NotFound(error.ModuleError):
|
||||
"""Program not found on ArteTV."""
|
||||
|
||||
|
||||
class UnsupportedProtocol(common.Error):
|
||||
class UnsupportedProtocol(error.ModuleError):
|
||||
"""Program type not supported."""
|
||||
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
"""Provide common utilities."""
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
"""General error."""
|
||||
class ModuleError(Exception):
|
||||
"""Module error."""
|
||||
|
||||
def __str__(self):
|
||||
"""Use the class definition docstring as a string representation."""
|
||||
|
@ -16,5 +16,5 @@ class Error(Exception):
|
|||
return f"{self.__class__.__qualname__}{self.args!r}"
|
||||
|
||||
|
||||
class UnexpectedError(Error):
|
||||
class UnexpectedError(ModuleError):
|
||||
"""An error to report to developers."""
|
|
@ -66,7 +66,7 @@ from tempfile import NamedTemporaryFile
|
|||
import m3u8
|
||||
import webvtt
|
||||
|
||||
from . import common, model
|
||||
from . import error, model
|
||||
|
||||
#
|
||||
# WARNING !
|
||||
|
@ -84,7 +84,7 @@ from . import common, model
|
|||
# - Subtitles media playlists have only one segment
|
||||
|
||||
|
||||
class UnexpectedResponse(common.UnexpectedError):
|
||||
class UnexpectedResponse(error.UnexpectedError):
|
||||
"""Unexpected response from ArteTV."""
|
||||
|
||||
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
"""Provide ArteTV website utilities."""
|
||||
|
||||
from . import common
|
||||
from . import error
|
||||
|
||||
BASE = "https://www.arte.tv/"
|
||||
LANGUAGES = ["fr", "de", "en", "es", "pl", "it"]
|
||||
|
||||
|
||||
class InvalidUrl(common.Error):
|
||||
class InvalidUrl(error.ModuleError):
|
||||
"""Invalid ArteTV URL."""
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue