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

Return status code 1 from sync command on warnings/errors #289

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions b2/_internal/b2v3/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from b2._internal._cli.b2api import _get_b2api_for_profile
from b2._internal.arg_parser import enable_camel_case_arguments
from .rm import Rm
from .sync import Sync

enable_camel_case_arguments()

Expand Down
16 changes: 16 additions & 0 deletions b2/_internal/b2v3/sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
######################################################################
#
# File: b2/_internal/b2v3/sync.py
#
# Copyright 2024 Backblaze Inc. All Rights Reserved.
#
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################

from b2._internal.b2v4.registry import Sync as SyncV4


class Sync(SyncV4):
__doc__ = SyncV4.__doc__
FAIL_ON_REPORTER_ERRORS_OR_WARNINGS = False
4 changes: 4 additions & 0 deletions b2/_internal/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2972,6 +2972,8 @@ class Sync(
DEFAULT_DOWNLOAD_THREADS = 10
DEFAULT_UPLOAD_THREADS = 10

FAIL_ON_REPORTER_ERRORS_OR_WARNINGS = True

@classmethod
def _setup_parser(cls, parser):
add_normalized_argument(parser, '--no-progress', action='store_true')
Expand Down Expand Up @@ -3089,6 +3091,8 @@ def _run(self, args):
raise CommandError(f'{ex.path} is not a directory')
except UnableToCreateDirectory as ex:
raise CommandError(f'unable to create directory {ex.path}')
if self.FAIL_ON_REPORTER_ERRORS_OR_WARNINGS and reporter.has_errors_or_warnings():
return 1
return 0

def get_policies_manager_from_args(self, args):
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+sync-status-code.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed `sync` command exit status code from 0 to 1 if any warnings or errors were encountered during the operation.
8 changes: 4 additions & 4 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ classifiers = [
dependencies = [
"argcomplete>=2,<4",
"arrow>=1.0.2,<2.0.0",
"b2sdk>=2.1.0,<3",
"b2sdk>=2.2.0,<3",
"docutils>=0.18.1",
"idna~=3.4; platform_system == 'Java'",
"importlib-metadata>=3.3; python_version < '3.8'",
Expand Down
Loading