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

Add CPLErrorOnce() and CPLDebugOnce() #11606

Merged
merged 3 commits into from
Jan 9, 2025
Merged

Conversation

rouault
Copy link
Member

@rouault rouault commented Jan 8, 2025

to emit an error/debug message only once during the life-time of a process.

to emit an error/debug message only once during the life-time of
a process.
@rouault rouault added code enhancements Code enhancements (generally developer-only visible) funded through GSP Work funded through the GDAL Sponsorship Program labels Jan 8, 2025
@rouault rouault added this to the 3.11.0 milestone Jan 8, 2025
@coveralls
Copy link
Collaborator

coveralls commented Jan 8, 2025

Coverage Status

coverage: 70.075% (-0.001%) from 70.076%
when pulling fb37e01 on rouault:CPLErrorOnce
into 1d3a440 on OSGeo:master.

@sgillies
Copy link
Contributor

sgillies commented Jan 8, 2025

@rouault like Python warnings, then? Use it in code as many times as we want, but a unique error message/code combination appears no more than once?

@rouault
Copy link
Member Author

rouault commented Jan 8, 2025

like Python warnings, then? Use it in code as many times as we want, but a unique error message/code combination appears no more than once?

yes, this just institutionalizes a practice that has been done at hand up to now. Some GDAL errors/warnings are sometimes in tight loops or would be too frequently emitted.

@dbaston
Copy link
Member

dbaston commented Jan 9, 2025

This is a nice addition. I had a couple of ideas, please feel free to disregard:

  • should we allow the warning to be raised a small N number of times? Since the implementation isn't testing the uniqueness of the message I can imagine cases where seeing a message like "Value %d for field %s does not fit into a short and will be clamped." with a few different values of %d and %s could make it easier to understand the source of the error.
  • should we automatically append something like "Further messages of this type will be suppressed" to the text?

@rouault
Copy link
Member Author

rouault commented Jan 9, 2025

  • should we allow the warning to be raised a small N number of times?

I can see the point, but dont' feel like going into that complication currently.

should we automatically append something like "Further messages of this type will be suppressed" to the text?

good idea, done

@rouault rouault merged commit 6713bba into OSGeo:master Jan 9, 2025
36 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code enhancements Code enhancements (generally developer-only visible) funded through GSP Work funded through the GDAL Sponsorship Program
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants