Skip to content

Commit 286de1a

Browse files
committed
[Added][CLI] --fail-on-warnings
To return error when we detected warning See #828
1 parent 9487895 commit 286de1a

7 files changed

Lines changed: 20 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99
### Added
10+
- CLI:
11+
- --fail-on-warnings: to return error when we detected warning (See #828)
1012
- iBoM: `mark_when_checked` option (#881)
1113

1214

docs/source/Changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Versioning <https://semver.org/spec/v2.0.0.html>`__.
1919
Added
2020
~~~~~
2121

22+
- CLI:
23+
24+
- –fail-on-warnings: to return error when we detected warning (See
25+
#828)
26+
2227
- iBoM: ``mark_when_checked`` option (#881)
2328

2429
`1.8.5 <https://github.com/INTI-CMNB/KiBot/compare/v1.8.4...v1.8.5>`__ - 2025-11-26

docs/source/errors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ Supported error levels
4242
- 36: WARN_AS_ERROR
4343
- 37: CHECK_FIELD
4444
- 38: IGNORED_ERRORS
45+
- 39: GOT_WARNINGS

docs/source/usage.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Options:
5151
-F, --fail-on-ignored Return an error code if we skipped a fail.
5252
Used in conjunction with -D and `dont_stop`
5353
options
54+
--fail-on-warnings Return an error code if we informed warnings.
5455
-g DEF, --global-redef DEF Overwrite a global value (VAR=VAL)
5556
--gui Open a graphic dialog
5657
--internal-check Run some outputs internal checks

kibot/__main__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
-F, --fail-on-ignored Return an error code if we skipped a fail.
5959
Used in conjunction with -D and `dont_stop`
6060
options
61+
--fail-on-warnings Return an error code if we informed warnings.
6162
-g DEF, --global-redef DEF Overwrite a global value (VAR=VAL)
6263
--gui Open a graphic dialog
6364
--internal-check Run some outputs internal checks
@@ -153,7 +154,7 @@
153154
from .gs import GS
154155
from . import dep_downloader
155156
from .misc import (EXIT_BAD_ARGS, W_VARCFG, NO_PCBNEW_MODULE, W_NOKIVER, hide_stderr, TRY_INSTALL_CHECK, W_ONWIN,
156-
FAILED_EXECUTE, W_ONMAC, IGNORED_ERRORS)
157+
FAILED_EXECUTE, W_ONMAC, IGNORED_ERRORS, GOT_WARNINGS)
157158
from .pre_base import BasePreFlight
158159
from .config_reader import (print_outputs_help, print_output_help, print_preflights_help, create_example, print_filters_help,
159160
print_global_options_help, print_dependencies, print_variants_help, print_errors,
@@ -668,6 +669,9 @@ def main():
668669
if args.fail_on_ignored and (GS.errors_ignored or log.errors_ignored):
669670
exit(IGNORED_ERRORS)
670671

672+
if args.fail_on_warnings and logger.got_warnings():
673+
exit(GOT_WARNINGS)
674+
671675

672676
if __name__ == "__main__":
673677
main() # pragma: no cover

kibot/log.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ def log_totals(self):
203203
filt_msg = ', {} filtered'.format(MyLogger.n_filtered)
204204
self.info('Found {} unique warning/s ({} total{})'.format(MyLogger.warn_cnt, MyLogger.warn_tcnt, filt_msg))
205205

206+
def got_warnings(self):
207+
return MyLogger.warn_cnt or MyLogger.warn_tcnt
208+
206209
def non_critical_error(self, msg, *args, **kwargs):
207210
buf = str(msg)
208211
push_error_msg(buf)

kibot/misc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
WARN_AS_ERROR = 36
5353
CHECK_FIELD = 37
5454
IGNORED_ERRORS = 38
55+
GOT_WARNINGS = 39 # Not treated as errors, but using `--fail-on-warnings`
5556
error_level_to_name = ['NONE',
5657
'INTERNAL_ERROR',
5758
'WRONG_ARGUMENTS',
@@ -90,7 +91,8 @@
9091
'BLENDER_ERROR',
9192
'WARN_AS_ERROR',
9293
'CHECK_FIELD',
93-
'IGNORED_ERRORS'
94+
'IGNORED_ERRORS',
95+
'GOT_WARNINGS'
9496
]
9597
KICOST_SUBMODULE = '../submodules/KiCost/src/kicost'
9698
EXAMPLE_CFG = 'example_template.kibot.yaml'

0 commit comments

Comments
 (0)