Fix: Raise an Error for Wrong Input or Output File Formats in Artbox #157 #240
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.
Users could specify incorrect file formats for input/output paths without receiving validation errors. For example, using --output-path /tmp/artbox/speech.md (text format) instead of speech.mp3 (audio format) for text to speech conversion would complete without error, causing downstream operations to fail.
Solution
= Implemented file format validation for Artbox CLI operations:
New Files:
= validators.py - Validator module with validate_io_paths() function
Changes:
= Validates input/output file extensions based on operation type:
text-to-speech (tts): requires audio output (.mp3, .wav, .ogg, .flac, .m4a, .aac)
speech-to-text (stt): requires audio input and text output (.txt, .md, .srt, .vtt, .json)
Infers operation type from file extensions if not explicitly provided
Raises clear, user-friendly error messages with supported format lists
Exits with code 2 on validation failure
Modified Files:
Benefits
Test: text to speech with invalid .md output (should fail)
python src/artbox/validators.py --operation text-to-speech --output-path out.md
Test: speech to text with valid formats (should pass)
python src/artbox/validators.py --operation speech-to-text --input-path audio.mp3 --output-path transcript.txt