fix(check-licenses): print message on exceptions while loading a file#3732
Open
fix(check-licenses): print message on exceptions while loading a file#3732
Conversation
tiborsimko
reviewed
Apr 28, 2025
| message = f"Failed to load {path.name} because of {type(e).__name__}: {e}" | ||
|
|
||
| logging.error(message) | ||
| raise e |
Member
There was a problem hiding this comment.
This works well, but in the case of testing many files, the error message may get "lost" in the middle:
$ python3 ./scripts/check_licenses.py
...
[INFO] Successfully validated file atlas-2020-4lep.json
[INFO] Successfully validated file lhcb-antimatter-matters-2017.json
[INFO] Successfully validated file jade-computing-notes.json
[INFO] Successfully validated file cms-simulated-datasets-2015-part_11.json
[INFO] Successfully validated file atlas-2024-mc-pp-exotics-nominal.json
[ERROR] Failed to load mytest.json because of JSONDecodeError: Extra data: line 402 column 4 (char 13334)
[INFO] Successfully validated file LHCb_2011_Beam3500GeV_VeloClosed_MagDown_RealData_Reco14_Stripping21r1p1a_DIMUON_DST.json
[INFO] Successfully validated file LHCb_2011_Beam3500GeV_VeloClosed_MagUp_RealData_Reco14_Stripping21r1_BHADRONCOMPLETEEVENT_DST.json
[INFO] Successfully validated file opera-detector-events-charm.json
[INFO] Successfully validated file cms-simulated-datasets-Run2011A.json
[INFO] Successfully validated file cms-tools-nanoaod-outreach-higgstautau.json
...
[INFO] Processed 329 files within 1.09 seconds.
[ERROR] Validation completed with 1 errors!
Please ensure the licenses are one of the following: ['CC0-1.0', 'GPL-3.0-only', 'MIT', 'Apache-2.0', 'BSD-3-Clause'].
If you are using a valid SPDX license string that is not in the above list, please contact `opendata-team@cern.ch`.If output has 330 lines, the ERROR messages are getting a bit "lost" in the output.
Possible solutions:
- Repeat the error situation at the end, indicating which files failed, basically giving a summary like "329 files tested, 1 error found (
mydata.json)", similarly to howpytestbehaves. - As also suggested by Pablo in the issue, please demote INFO info DEBUG, so that these success messages would not be unnecessarily printed, and would not obscure the picture. (This is usually how linters work, only output errors and warnings.) If a user wants to see them, they could increase loglevel by a command-line option
BTW some other cosmetic remarks:
- Cosmetics: BTW we may also want to process the input files in some nice alphabetical order for easier orientation in the outputs?
- Cosmetics: While you are at editing this script, please amend the header to use
#!/usr/bin/env python3i.e. the Python version 3 included. Helps on some systems where there are onlypython2andpython3executables.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3731