Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source File: Handle network errors #25641

Merged
merged 6 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from os import environ
from typing import Iterable
from urllib.parse import urlparse
from urllib3.exceptions import ProtocolError

import backoff
import boto3
Expand Down Expand Up @@ -396,6 +397,12 @@ def read(self, fields: Iterable = None) -> Iterable[dict]:
except ConnectionResetError:
logger.info(f"Catched `connection reset error - 104`, stream: {self.stream_name} ({self.reader.full_url})")
raise ConnectionResetError
except ProtocolError as err:
bazarnov marked this conversation as resolved.
Show resolved Hide resolved
error_msg = (
f"File {fp} can not be opened due to connection issues on provider side. Please check provided links and options"
)
logger.error(f"{error_msg}\n{traceback.format_exc()}")
raise ConfigurationError(error_msg) from err

def _cache_stream(self, fp):
"""cache stream to file"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pytest
from pandas import read_csv, read_excel
from urllib3.exceptions import ProtocolError
from source_file.client import Client, ConfigurationError, URLFile


Expand Down Expand Up @@ -150,3 +151,11 @@ def test_read(test_read_config):
except ConnectionResetError:
print("Exception has been raised correctly!")
mock_method.assert_called()


def test_read_network_issues(test_read_config):
test_read_config.update(format='excel')
client = Client(**test_read_config)
client.sleep_on_retry_sec = 0 # just for test
with patch.object(client, "_cache_stream", side_effect=ProtocolError), pytest.raises(ConfigurationError):
next(client.read(["date", "key"]))