Skip to content

Commit f543b69

Browse files
authored
feat: error- and debug-output is send to STDERR, instead of STDOUT (#465)
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent de188b8 commit f543b69

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

cyclonedx_py/client.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,25 @@ def get_output(self) -> BaseOutput:
8383
try:
8484
parser = self._get_input_parser()
8585
except CycloneDxCmdNoInputFileSupplied as e:
86-
print(f'ERROR: {str(e)}')
86+
print(f'ERROR: {str(e)}', file=sys.stderr)
8787
exit(1)
8888
except CycloneDxCmdException as e:
89-
print(f'ERROR: {str(e)}')
89+
print(f'ERROR: {str(e)}', file=sys.stderr)
9090
exit(1)
9191

9292
if parser and parser.has_warnings():
93-
print('')
94-
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
95-
print('!! Some of your dependencies do not have pinned version !!')
96-
print('!! numbers in your requirements.txt !!')
97-
print('!! !!')
98-
for warning in parser.get_warnings():
99-
print('!! -> {} !!'.format(warning.get_item().ljust(49)))
100-
print('!! !!')
101-
print('!! The above will NOT be included in the generated !!')
102-
print('!! CycloneDX as version is a mandatory field. !!')
103-
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
104-
print('')
93+
print('',
94+
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!',
95+
'!! Some of your dependencies do not have pinned version !!',
96+
'!! numbers in your requirements.txt !!',
97+
'!! !!',
98+
*('!! -> {} !!'.format(warning.get_item().ljust(49)) for warning in parser.get_warnings()),
99+
'!! !!',
100+
'!! The above will NOT be included in the generated !!',
101+
'!! CycloneDX as version is a mandatory field. !!',
102+
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!',
103+
'',
104+
sep='\n', file=sys.stderr)
105105

106106
bom = Bom.from_parser(parser=parser)
107107

@@ -147,7 +147,7 @@ def execute(self) -> None:
147147
output = self.get_output()
148148
if self._arguments.output_file == '-' or not self._arguments.output_file:
149149
self._debug_message('Returning SBOM to STDOUT')
150-
print(output.output_as_string())
150+
print(output.output_as_string(), file=sys.stdout)
151151
return
152152

153153
# Check directory writable
@@ -242,11 +242,11 @@ def get_arg_parser(*, prog: Optional[str] = None) -> argparse.ArgumentParser:
242242

243243
def _debug_message(self, message: str) -> None:
244244
if self._DEBUG_ENABLED:
245-
print('[DEBUG] - {} - {}'.format(datetime.now(), message))
245+
print('[DEBUG] - {} - {}'.format(datetime.now(), message), file=sys.stderr)
246246

247247
@staticmethod
248248
def _error_and_exit(message: str, exit_code: int = 1) -> None:
249-
print('[ERROR] - {} - {}'.format(datetime.now(), message))
249+
print('[ERROR] - {} - {}'.format(datetime.now(), message), file=sys.stderr)
250250
exit(exit_code)
251251

252252
def _get_input_parser(self) -> BaseParser:

0 commit comments

Comments
 (0)