B2_Command_Line_Tool icon indicating copy to clipboard operation
B2_Command_Line_Tool copied to clipboard

Downloading to a dir that doesn't exist throws a raw Python error

Open molomby opened this issue 5 years ago • 0 comments

Attempting to download a file but specifying a local filename in a dir that doesn't exist causes throws an unfriendly error. Eg..

b2 download-file-by-id $FILE_ID "this-dir-does-not-exist/stuff.zip"

Throws..

Traceback (most recent call last):
	File "/usr/local/bin/b2", line 8, in <module>
		sys.exit(main())
	File "/usr/local/lib/python2.7/site-packages/b2/console_tool.py", line 1619, in main
		exit_status = ct.run_command(decoded_argv)
	File "/usr/local/lib/python2.7/site-packages/b2/console_tool.py", line 1476, in run_command
		return command.run(args)
	File "/usr/local/lib/python2.7/site-packages/b2/console_tool.py", line 630, in run
		self.api.download_file_by_id(args.fileId, download_dest, progress_listener)
	File "/usr/local/lib/python2.7/site-packages/logfury/v0_1/trace_call.py", line 84, in wrapper
		return function(*wrapee_args, **wrapee_kwargs)
	File "/usr/local/lib/python2.7/site-packages/b2sdk/api.py", line 251, in download_file_by_id
		return self.transferer.download_file_from_url(url, download_dest, progress_listener, range_)
	File "/usr/local/lib/python2.7/site-packages/logfury/v0_1/trace_call.py", line 84, in wrapper
		return function(*wrapee_args, **wrapee_kwargs)
	File "/usr/local/lib/python2.7/site-packages/b2sdk/transferer/transferer.py", line 102, in download_file_from_url
		range_=range_,
	File "/usr/local/Cellar/python@2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
		return self.gen.next()
	File "/usr/local/lib/python2.7/site-packages/b2sdk/download_dest.py", line 215, in write_file_and_report_progress_context
		mod_time_millis, range_
	File "/usr/local/Cellar/python@2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
		return self.gen.next()
	File "/usr/local/lib/python2.7/site-packages/b2sdk/download_dest.py", line 110, in write_to_local_file_context
		os.unlink(self.local_file_path)
OSError: [Errno 2] No such file or directory: 'this-dir-does-not-exist/stuff.zip'

A nicer error would be better, as per #611. Better yet would be an option (default?) to create dirs specified in this way. This would match the behaviour when uploading.

molomby avatar May 09 '20 05:05 molomby