zamzar / zamzar-bash

Bash Command Line Interface for the Zamzar API - convert files to 100s of formats direct from the command line.
MIT License
17 stars 5 forks source link

Files with double space fail ungracefully (disgracefully ?) #3

Closed whyleyc closed 9 years ago

whyleyc commented 9 years ago

Currently if you try and upload a file larger than the filesize cap (e.g. for Sandbox) the bash script gallantly ploughs on and gets itself mightily confused when trying to find the right file to download (since the job never started it looks at all files ever converted).

We should look for the following error on job submission and exit early if we hit it (with an informational error):

{"errors":[{"code":25,"message":"the size of file exceeds the maximum file size cap for the current plan","context":{"file_size":1861263,"maximum_file_size":1048576}}]}

We likely want to implement this in such a way that we don't just search for this particular error but exit early on any error since there will be other edge cases too (e.g. running out of credits).

louismrose commented 9 years ago

Hmm, I can't seem to reproduce this:

> ./zamzar.sh ~/Downloads/large.rar zip
Error(s) were encountered whilst issuing an API request.
  Request: curl -L https://sandbox.zamzar.com/v1/jobs -X POST -F "source_file=@/Users/louis/Downloads/large.rar" -F "target_format=zip" --silent -u REDACTED:
  Errors:
    {"errors":[{"code":25,"message":"the size of file exceeds the maximum file size cap for the current plan","context":{"file_size":1441923,"maximum_file_size":1048576}}]}

This was a for a file of 1.5 MB on the test plan (which seems to allow 1MB files). The error is caught and printed the logic on lines 183 - 190.

Could you point me at a file and target format that surfaces this one @whyleyc ?

whyleyc commented 9 years ago

@louismrose I just re-tested and it looks like the issue only surfaces when the input file has spaces in it ?

louismrose commented 9 years ago

@whyleyc Hmm, I still can't reproduce! I tried renaming my 1.5MB input file to "large archive.rar" and I still received the error message as expected.

whyleyc commented 9 years ago

@louismrose It turns out the culprit is a double space ! Try "large archive.rar". The file fails submission even when submitted to live so this is probably a wider issue than just files which are too big for the sandbox. Feel free to give me a shout if the bash gets too murky.

louismrose commented 9 years ago

@whyleyc Well, that was tricky! I learnt more about Bash's IFS than is possibly healthy. However, I think I fixed the issue and in a manner that works with multiple target files, and with filenames containing other exotic characters.

whyleyc commented 9 years ago

I had no idea this rabbit hole existed !

Great work fixing - I'll register "Bash Consultancy Services Ltd" this afternoon.