-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Improve error messages for missing or invalid files #51
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,8 +20,8 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @click.command() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @click.argument("file_a", type=click.Path(exists=True)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @click.argument("file_b", type=click.Path(exists=True)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @click.argument("file_a", type=click.Path()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @click.argument("file_b", type=click.Path()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @click.option( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--format", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "output_format", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -65,6 +65,31 @@ def main( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compares FILE_A (reference) against FILE_B (comparison) and reports | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| differences in loudness, spectral content, timing, and potential issues. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console = Console() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The Suggested FixPass the Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validation messages should use stderr and honor
Proposed fix- console = Console()
+ console = Console(stderr=True, no_color=no_color)📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Validate file_a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path_a = pathlib.Path(file_a) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not path_a.exists(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.print(f"[red]Error:[/red] File not found: [bold]{file_a}[/bold]") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.print(f"[dim]Looked in: {path_a.parent.absolute()}[/dim]") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.print("[dim]Tip: Check the file path and make sure the file exists.[/dim]") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sys.exit(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Validate file_b | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path_b = pathlib.Path(file_b) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not path_b.exists(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.print(f"[red]Error:[/red] sounddiff needs two files to compare.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.print(f"[dim]Got: {file_a} (exists), but {file_b} not found.[/dim]") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.print(f"[dim]Looked in: {path_b.parent.absolute()}[/dim]") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sys.exit(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+71
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existence-only checks miss invalid path types (e.g., directories).
Proposed fix path_a = pathlib.Path(file_a)
if not path_a.exists():
console.print(f"[red]Error:[/red] File not found: [bold]{file_a}[/bold]")
console.print(f"[dim]Looked in: {path_a.parent.absolute()}[/dim]")
console.print("[dim]Tip: Check the file path and make sure the file exists.[/dim]")
sys.exit(1)
+ if not path_a.is_file():
+ console.print(f"[red]Error:[/red] Not a file: [bold]{file_a}[/bold]")
+ sys.exit(1)
path_b = pathlib.Path(file_b)
if not path_b.exists():
console.print(f"[red]Error:[/red] sounddiff needs two files to compare.")
console.print(f"[dim]Got: {file_a} (exists), but {file_b} not found.[/dim]")
console.print(f"[dim]Looked in: {path_b.parent.absolute()}[/dim]")
sys.exit(1)
+ if not path_b.is_file():
+ console.print(f"[red]Error:[/red] Not a file: [bold]{file_b}[/bold]")
+ sys.exit(1)As per coding guidelines, 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Validate audio file extensions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audio_extensions = {'.wav', '.mp3', '.flac', '.ogg', '.m4a', '.aac', '.wma', '.aiff', '.aif'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for file_path, arg_name in [(path_a, 'FILE_A'), (path_b, 'FILE_B')]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if file_path.suffix.lower() not in audio_extensions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.print(f"[yellow]Warning:[/yellow] {arg_name} ('{file_path.name}') may not be an audio file.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.print(f"[dim]Expected audio formats: {', '.join(sorted(audio_extensions))}[/dim]") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+87
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded extension list is already stale ( This duplicates format definitions and drifts from Proposed fix-from sounddiff.formats import FFMPEG_FORMATS
+from sounddiff.formats import FFMPEG_FORMATS, NATIVE_FORMATS
...
- audio_extensions = {'.wav', '.mp3', '.flac', '.ogg', '.m4a', '.aac', '.wma', '.aiff', '.aif'}
+ audio_extensions = NATIVE_FORMATS | FFMPEG_FORMATS📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Best-effort duration probe: if sf.info() fails for either file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # skip the progress bar and let diff() raise the proper error message. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| show_progress = False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: systemblueteam/sounddiff
Length of output: 3944
🏁 Script executed:
Repository: systemblueteam/sounddiff
Length of output: 238
🏁 Script executed:
# Get the full cli.py file to understand the actual implementation wc -l src/sounddiff/cli.pyRepository: systemblueteam/sounddiff
Length of output: 92
🏁 Script executed:
# Check formats.py to verify the claim about NATIVE_FORMATS and FFMPEG_FORMATS cat -n src/sounddiff/formats.pyRepository: systemblueteam/sounddiff
Length of output: 5514
🏁 Script executed:
Repository: systemblueteam/sounddiff
Length of output: 209
🏁 Script executed:
Repository: systemblueteam/sounddiff
Length of output: 300
Click validates argument arity before calling
main(), so single-file invocation won't reach your custom error message.With two required
click.argumentdecorators, Click exits withMissing argument 'FILE_B'before the function runs. To provide a custom error message for the single-file case (issue#50), change to variable args and validate in the function:Suggested fix
Also fix the
exists()validation to reject directories (file_path.is_file()instead offile_path.exists()), and add.opusto the hardcoded extensions (currently inFFMPEG_FORMATSbut missing from the local list on line 87).