NotFound exceptions from remove_#{column}! and remove_previously_stored_#{column}

177 views
Skip to first unread message

scottwb

unread,
Jul 10, 2011, 1:22:17 PM7/10/11
to carrierwave
The model callbacks remove_#{column}! and
remove_previously_stored_#{column}, which get invoked after a
`destroy` or `save`, respectively, raise NotFound exceptions if the
uploaded file that `column` references no longer exists. In my case,
this is a Fog::Storage::Rackspace::NotFound exception, since I am
using Rackspace Cloud Files for storage.

I am not sure yet why I end up with dangling references to files that
have already been removed. I think it might have to do with a model
validation failing after remove_previously_stored_#{column} was
called, leaving my file removed, but my record not updated.

Regardless of how I got there, I was thinking that these exceptions
should be silently ignored. After all, if the intention is to remove
the file, then the file being missing is not a fatal error. At least
for my app, I don't want a user to never be able to upload a new
avatar just because the old one is gone. I can imagine, however, that
there may be others who prefer to get this exception as an indicator
of something else being wrong. So, rather than make a patch that
ignores these exceptions directly in original implementation, I chose
to override these two methods in my model class like so:

https://gist.github.com/1074704

I wanted to run this by the maintainers and those more familiar with
the project. Is this an appropriate solution? Should this be rolled
into the main line with support for all the other storage providers
and test cases? Is there a better way? If you let me know your
opinions, I'd be happy to take a stab at a pull request or a wiki
article or whatever.

Cheers,
-Scott

Trevor Turk

unread,
Jul 10, 2011, 2:54:46 PM7/10/11
to carri...@googlegroups.com
I think rescuing is the right thing for you to do here, given that you're aware that there are "dangling references to files that have already been removed" that you're not overly concerned with. If you want to work up a wiki "how to" page, go for it!

scottwb

unread,
Jul 10, 2011, 10:09:02 PM7/10/11
to carrierwave
Thanks for the advice Trevor. I've added a How-To page to the wiki:
https://github.com/jnicklas/carrierwave/wiki/How-To:-Silently-ignore-missing-files-on-destroy-or-overwrite
Reply all
Reply to author
Forward
0 new messages