Skip to content

Commit e0d17e3

Browse files
Print OBJ plugin errors to stderr (#737)
1 parent 69f3c69 commit e0d17e3

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

linodecli/plugins/obj/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ def set_acl(get_client, args, **kwargs): # pylint: disable=unused-argument
173173

174174
try:
175175
set_acl_func(**set_acl_options)
176-
except ClientError:
176+
except ClientError as e:
177+
print(e, file=sys.stderr)
177178
sys.exit(ExitCodes.REQUEST_FAILED)
178179
print("ACL updated")
179180

@@ -203,14 +204,16 @@ def show_usage(get_client, args, **kwargs): # pylint: disable=unused-argument
203204
bucket_names = [
204205
b["Name"] for b in client.list_buckets().get("Buckets", [])
205206
]
206-
except ClientError:
207+
except ClientError as e:
208+
print(e, file=sys.stderr)
207209
sys.exit(ExitCodes.REQUEST_FAILED)
208210

209211
grand_total = 0
210212
for b in bucket_names:
211213
try:
212214
objects = client.list_objects_v2(Bucket=b).get("Contents", [])
213-
except ClientError:
215+
except ClientError as e:
216+
print(e, file=sys.stderr)
214217
sys.exit(ExitCodes.REQUEST_FAILED)
215218
total = 0
216219
obj_count = 0
@@ -358,7 +361,8 @@ def call(
358361
# we can't do anything - ask for an install
359362
print(
360363
"This plugin requires the 'boto3' module. Please install it by running "
361-
"'pip3 install boto3' or 'pip install boto3'"
364+
"'pip3 install boto3' or 'pip install boto3'",
365+
file=sys.stderr,
362366
)
363367

364368
sys.exit(

linodecli/plugins/obj/objects.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ def upload_object(
8181
for f in files:
8282
file_path = Path(f).resolve()
8383
if not file_path.is_file():
84+
print(
85+
f"Error: '{file_path}' is not a valid file or does not exist.",
86+
file=sys.stderr,
87+
)
8488
sys.exit(ExitCodes.FILE_ERROR)
8589

8690
to_upload.append(file_path)
@@ -112,7 +116,8 @@ def upload_object(
112116
)
113117
try:
114118
client.upload_file(**upload_options)
115-
except S3UploadFailedError:
119+
except S3UploadFailedError as e:
120+
print(e, file=sys.stderr)
116121
sys.exit(ExitCodes.REQUEST_FAILED)
117122

118123
print("Done.")
@@ -174,7 +179,8 @@ def get_object(
174179
# In the future we should allow the automatic creation of parent directories
175180
if not destination_parent.exists():
176181
print(
177-
f"ERROR: Output directory {destination_parent} does not exist locally."
182+
f"ERROR: Output directory {destination_parent} does not exist locally.",
183+
file=sys.stderr,
178184
)
179185
sys.exit(ExitCodes.REQUEST_FAILED)
180186

0 commit comments

Comments
 (0)