Skip to content

registry/search: warn instead of silently coercing bad limit values#196

Open
SoundMatt wants to merge 1 commit into
COVESA:mainfrom
SoundMatt:fix/parse-limit-warn-on-coerce
Open

registry/search: warn instead of silently coercing bad limit values#196
SoundMatt wants to merge 1 commit into
COVESA:mainfrom
SoundMatt:fix/parse-limit-warn-on-coerce

Conversation

@SoundMatt
Copy link
Copy Markdown

Change

Add log.warning in the three coerce branches:

  • unparseable string (ValueError on int() conversion)
  • negative integer parsed from a string
  • negative integer passed directly

Return values are unchanged, so the existing assertions in test_parse_limit_method (e.g. parse_limit("invalid") == 0, parse_limit(-1) == 0) still pass — this is purely additive observability, not a behaviour change.

Tests

Three new tests in test_skos_search.py:

  • test_parse_limit_warns_on_unparseable_string — warning fires, return value still 0
  • test_parse_limit_warns_on_negative_int — warning fires, return value still 0
  • test_parse_limit_does_not_warn_on_zero0 and "0" are legitimate "no results requested" inputs and must NOT warn

Other changes

Switched src/s2dm/registry/search.py from stdlib logging to from s2dm import log to match the rest of the codebase (registry/spec_history.py and elsewhere) and so the warnings are caplog-testable via logger="s2dm". The existing logging.error(...) call elsewhere in the file is left untouched (out of scope).

Local verification: 535 tests pass.

SKOSSearchService.parse_limit silently coerced unparseable strings
and negative integers to 0. search_keyword treats limit_value == 0
as 'return no results', so a typo in --limit produced an empty
result list indistinguishable from 'no matches found'. The user
got no signal that their input was rejected.

Add log.warning in the three coerce branches:
  - unparseable string (ValueError on int() conversion)
  - negative integer parsed from a string
  - negative integer passed directly

Return values are unchanged, so the existing test_parse_limit_method
assertions still pass. Three new tests cover the warning paths and
verify that limit=0 (a legitimate user request for no results)
does NOT warn.

Switch the file from stdlib logging to the s2dm log module to match
the rest of the codebase (registry/spec_history.py and elsewhere)
and so the warnings are caplog-testable via logger='s2dm'.

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant