fix: validate reference arguments in api_client instead of failing silently - #1319
Open
yuvrajnode wants to merge 1 commit into
Open
fix: validate reference arguments in api_client instead of failing silently#1319yuvrajnode wants to merge 1 commit into
yuvrajnode wants to merge 1 commit into
Conversation
…lently The `__main__` block of tools/api_client.py built the `references` list in a way that discarded bad input without telling the user: 1. `audio_to_bytes()` returns None when the path does not exist, and the result was coerced with `audio=ref_audio if ref_audio is not None else b""`. A typo in --reference_audio therefore became an empty reference audio and was sent to the server, which fails later with an unrelated decode error. 2. `zip(ref_texts, byte_audios)` truncates to the shorter sequence. --reference_audio and --reference_text are separate `nargs="+"` options, so passing three audios and two texts silently dropped the third reference instead of reporting the mismatch. Both are easy to hit from the command line and neither produced any warning. Fail fast instead: report a missing reference audio by path, and require the two options to have matching lengths. With those checks in place the None coercion is no longer reachable, so `references` builds directly from the validated values. Behavior is unchanged when the arguments are correct, and when --reference_id is used or no references are passed at all.
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.
The
__main__block oftools/api_client.pybuilds thereferenceslist in a way that discards bad input without telling the user.Two silent failures
1. A missing reference audio becomes empty audio.
audio_to_bytes()returnsNonewhen the path does not exist, and the result was coerced withaudio=ref_audio if ref_audio is not None else b"". A typo in--reference_audiois therefore sent to the server as an empty reference, which fails later with an unrelated decode error rather than pointing at the bad path.2. Mismatched counts are truncated.
zip(ref_texts, byte_audios)stops at the shorter sequence.--reference_audioand--reference_textare separatenargs="+"options, so passing three audios and two texts silently drops the third reference.--reference_audioaudio=b""Reference audio file not found: typo.wav--reference_idFix
Fail fast: report a missing reference audio by path, and require the two options to have matching lengths. With those checks in place the
Nonecoercion is unreachable, soreferencesbuilds directly from the validated values.Behavior is unchanged when the arguments are correct, when
--reference_idis used, and when no references are passed at all.The repo has no test suite, so I kept this to the behavioral fix rather than introducing pytest as a new dependency.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.