Skip to content
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

Improve error message for bad seek positions. #359

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pedalboard/io/ReadableAudioFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,15 +572,20 @@ class ReadableAudioFile
const juce::ScopedReadLock scopedReadLock(objectLock);
if (!reader)
throw std::runtime_error("I/O operation on a closed file.");
if (targetPosition >
(reader->lengthInSamples + (lengthCorrection ? *lengthCorrection : 0)))

long long endOfFile =
(reader->lengthInSamples + (lengthCorrection ? *lengthCorrection : 0));

if (targetPosition > endOfFile)
throw std::domain_error(
"Cannot seek beyond end of file (" +
std::to_string(reader->lengthInSamples +
(lengthCorrection ? *lengthCorrection : 0)) +
" frames).");
"Cannot seek to position " + std::to_string(targetPosition) +
" frames, which is beyond end of file (" + std::to_string(endOfFile) +
" frames) by " + std::to_string(endOfFile - targetPosition) +
" frames.");

if (targetPosition < 0)
throw std::domain_error("Cannot seek before start of file.");
throw std::domain_error("Cannot seek before start of file (to position " +
std::to_string(targetPosition) + ").");

// Promote to a write lock as we're now modifying the object:
ScopedTryWriteLock scopedTryWriteLock(objectLock);
Expand Down
Loading