-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Files] - fixes and improvements (#4081)
* [Files] - support automatic reading when reading http + uts * support reading xif as text files * fixed bug when unicoding files from memory * changelog * exceptions docstring * arrange exceptions * trigger retry on connection errors * update exceptions * add reading file errors uts * handle exceptions of __read_git_file * changelog update * update pr num * changelog change-name * naming convensions * changelog
- Loading branch information
Showing
12 changed files
with
302 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
changes: | ||
- description: Fixed an issue where SDK would crash when trying to read files which are not encoded with utf-8 directly from memory. | ||
type: fix | ||
- description: Improved error handling when reading files locally, remotely or from git. | ||
type: feature | ||
pr_number: 4081 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,78 @@ | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
|
||
class FileReadError(IOError): | ||
pass | ||
""" | ||
Base class for errors reading files, catch this error to catch any error related to reading files | ||
""" | ||
|
||
def __init__(self, message: str, exc: Exception): | ||
super().__init__(message) | ||
self.original_exc = exc | ||
|
||
|
||
class FileWriteError(IOError): | ||
def __init__(self, path: Path, exc: Exception): | ||
self.original_exc = exc | ||
super().__init__(f"could not write file {path}, full error:\n{exc}") | ||
|
||
|
||
class LocalFileReadError(FileReadError): | ||
""" | ||
Raised when there was an issue reading files from local file system. | ||
""" | ||
|
||
def __init__(self, path: Path, exc: Exception): | ||
self.original_exc = exc | ||
super().__init__(f"file {path} could not be read, full error:\n{exc}") | ||
super().__init__(f"file {path} could not be read, error:\n{exc}", exc=exc) | ||
|
||
|
||
class MemoryFileReadError(FileReadError): | ||
""" | ||
Raised when there was an issue reading files from memory (as bytes) | ||
""" | ||
|
||
class FileContentReadError(FileReadError): | ||
def __init__(self, exc: Exception): | ||
super().__init__(f"file could not be read, full error:\n{exc}") | ||
super().__init__(f"file could not be read, error:\n{exc}", exc=exc) | ||
|
||
|
||
class FileLoadError(FileReadError): | ||
""" | ||
Raised when there was an issue to load a file into the requested object, e.g (as text, json, yml and so on) | ||
""" | ||
|
||
def __init__(self, exc: Exception, class_name: str, path: Optional[Path] = None): | ||
if path: | ||
message = f"Could not load file {path} as {class_name}" | ||
else: | ||
message = f"Could not load file as {class_name}" | ||
super().__init__(message, exc=exc) | ||
|
||
|
||
class GitFileReadError(FileReadError): | ||
""" | ||
Raised when there was an issue reading files from git (from remote/locally) | ||
""" | ||
|
||
def __init__(self, path: Path, tag: str, exc: Exception): | ||
super().__init__( | ||
f"Could not get file {path} from branch/commit {tag}, full_error:\n{exc}" | ||
f"Could not get file {path} from branch/commit {tag}, error:\n{exc}", | ||
exc=exc, | ||
) | ||
|
||
|
||
class HttpFileReadError(IOError): | ||
class HttpFileReadError(FileReadError): | ||
""" | ||
Raised when there was an issue retrieving a file via http-request / api call | ||
""" | ||
|
||
def __init__(self, url: str, exc: Exception): | ||
super().__init__(f"Could not read file from {url}, full error:\n{exc}") | ||
super().__init__(f"Could not read file from {url}, full error:\n{exc}", exc=exc) | ||
|
||
|
||
class UnknownFileError(ValueError): | ||
""" | ||
Raised when failing to automatically detect subclass of File object dynamically by file's suffix/name | ||
""" | ||
|
||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.