Skip to content

[bugfix] Reject invalid --kernel-size with a usage error instead of a traceback (#604) - #605

Open
goranai wants to merge 2 commits into
Breakthrough:mainfrom
goranai:bugfix/kernel-size-validation
Open

goranai wants to merge 2 commits into
Breakthrough:mainfrom
goranai:bugfix/kernel-size-validation

Conversation

@goranai

@goranai goranai commented Nov 10, 2026

Copy link
Copy Markdown

Closes #604

-k/--kernel-size of detect-content and detect-adaptive was passed to ContentDetector unchecked, so 1, even or negative values ended in a ValueError traceback. It is now validated in CliContext and reported as click.BadParameter, as --weights and --downscale already are:

Error: Invalid value for kernel-size: Kernel size must be an odd integer >= 3.

KernelSizeValue also accepted kernel-size = 1 from a config file, contrary to its docstring, and the detector then raised. It now rejects values below 3 (except -1 = auto), and its message says ">= 3", matching the CLI help, scenedetect.cfg and the docs.

Note: on the command line -k -1 is now also rejected with a usage error. The CLI help never documented -1 for -k (only the config file does), and today -k -1 crashes with the same traceback.

Tests: test_cli_kernel_size_rejects_invalid (3 CLI cases) and test_cli_kernel_size_config_file_rejects_one (2 config cases) fail on main (5 failed) and pass with this change (5 passed). In the full suite the only failures are 2 moviepy tests that fail the same way on main because moviepy is not installed locally.

AI disclosure: prepared with Claude Code (Claude Opus 5.5) and reviewed by me.

🤖 Generated with Claude Code

… traceback (Breakthrough#604)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Breakthrough Breakthrough left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, have a few small changes to ask, but other than these LGTM.

Comment thread scenedetect/_cli/context.py Outdated
return parsed.frame_num

@staticmethod
def _validate_kernel_size(kernel_size: int | None) -> int | None:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we re-use KernelSizeValue here the same way --crop uses CropValue? That would also let -k -1 mean auto, like the config file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 4a4b66e. -k now goes through KernelSizeValue, like --crop uses CropValue, so -k -1 means auto and a bad value gives a usage error.

Comment thread tests/test_cli.py
[
["detect-content", "-k", "1"],
["detect-content", "-k", "4"],
["detect-adaptive", "-k", "1"],

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add cases for -k -1 and a negative value, plus a valid size (e.g. -k 3) that should succeeds?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 4a4b66e: -k -3 and -k -2 are rejected, and -k 3 and -k -1 succeed, for both detect-content and detect-adaptive.

self._value = None
elif value < 0:
# Disallow other negative values.
elif value < 3:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a changelog entry (at the very bottom under 0.8, website/pages/changelog.md), noting that kernel-size = 1 in a config file is now going to be an error.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the changelog entry under 0.8 in 4a4b66e, noting that kernel-size = 1 in a config file is now an error.

)

Adds tests for -k -1, negative and valid sizes, and a changelog entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@goranai

goranai commented Nov 13, 2026

Copy link
Copy Markdown
Author

All three points are done in 4a4b66e: -k goes through KernelSizeValue, the tests cover -k -3, -2, 3 and -1, and the changelog has the 0.8 entry. Could you take another look when you have time?

This branch has not been deployed

No deployments
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.

detect-content / detect-adaptive -k with an invalid kernel size crashes with a traceback; config accepts kernel-size = 1

3 participants