Remove implementation-dependent information from an error message #2499
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.
The message for
CarrierWave::ProcessingError
used to includeThe message is used for ActiveRecord validation, and it is often shown for an end-user. This behavior has some downsides:
This change solves the problems by simply removing those information.
You may still retrieve the original error message with
CarrierWave::ProcessingError#cause
for debugging or programatic errorhandling.
Alternative solutions
I'm aware this change may be a bit controversial and have ideas of alternative solutions for the case. Please tell me if you think they are more preferred or you have yet another idea; I'm willing to amend this change so that you feel comfortable with it.
Adding an option
This changes the existing behavior and is breaking by nature. CarrierWave may have an opt-in configuration to enable the new behavior to avoid disruption. Such an option may also be useful to change the behavior depending on environments (e.g. development v.s. production).
Adding a logging infrastructure
With this change, you will no longer see the original error message when printing the error message, which is a common strategy when you encounter an unexpected exception. Although you can still use
CarrierWave::ProcessingError#cause
, it may make debugging difficult. An alternative logging may heal the pain. I actually have two options for logging.Just
Rails.logger.error
inCarrierWave::Validations::ActiveModel
This is so simple that it does not require any more description. However it does not work if you do not use Ruby on Rails, of course.
Add a method to retrieve an user-facing error message to
CarrierWave::UploadError
Leave the error message exposed with
CarrierWave::UploadError#message
as is, and instead add a method to retrieve a message which does not include potentially sensitive information. This is complicated, but developers can expect an exception carries a detailed message.