Skip to content

Commit 28844ba

Browse files
committed
minor - throw NoFilesFound exception on 404
1 parent 86f7ac0 commit 28844ba

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

awswrangler/s3/_read_text.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union
66

77
import boto3
8+
import botocore.exceptions
89
import pandas as pd
910
import pandas.io.parsers
1011
from pandas.io.common import infer_compression
@@ -77,18 +78,23 @@ def _read_text_file(
7778
) -> pd.DataFrame:
7879
boto3_session = _utils.ensure_session(boto3_session)
7980
mode, encoding, newline = _get_read_details(path=path, pandas_kwargs=pandas_kwargs)
80-
with open_s3_object(
81-
path=path,
82-
version_id=version_id,
83-
mode=mode,
84-
use_threads=use_threads,
85-
s3_block_size=-1, # One shot download
86-
encoding=encoding,
87-
s3_additional_kwargs=s3_additional_kwargs,
88-
newline=newline,
89-
boto3_session=boto3_session,
90-
) as f:
91-
df: pd.DataFrame = parser_func(f, **pandas_kwargs)
81+
try:
82+
with open_s3_object(
83+
path=path,
84+
version_id=version_id,
85+
mode=mode,
86+
use_threads=use_threads,
87+
s3_block_size=-1, # One shot download
88+
encoding=encoding,
89+
s3_additional_kwargs=s3_additional_kwargs,
90+
newline=newline,
91+
boto3_session=boto3_session,
92+
) as f:
93+
df: pd.DataFrame = parser_func(f, **pandas_kwargs)
94+
except botocore.exceptions.ClientError as e:
95+
if e.response["Error"]["Code"] == "404":
96+
raise exceptions.NoFilesFound(f"No files Found on: {path}.")
97+
raise e
9298
return _apply_partitions(df=df, dataset=dataset, path=path, path_root=path_root)
9399

94100

0 commit comments

Comments
 (0)