for (Map.Entry<String, Screen> entry : workflow.getScreensByCommand().entrySet()) {
String commandKey = entry.getKey();
- if (!verifyConditions || verifyConditions(null, context, workflow.getContextConditions(commandKey))) {
+ if (!verifyConditions || verifyConditionsQuietly(null, context, workflow.getContextConditions(commandKey))) {
for (Review review : reviews) {
- if (!verifyConditions || verifyConditions(review, context, workflow.getReviewConditions(commandKey))) {
+ if (!verifyConditions || verifyConditionsQuietly(review, context, workflow.getReviewConditions(commandKey))) {
result.put(review.getViolationId(), entry.getValue());
}
}
completeProjectSettings(context);
for (Map.Entry<String, Screen> entry : workflow.getScreensByCommand().entrySet()) {
String commandKey = entry.getKey();
- if (!verifyConditions || verifyConditions(review, context, workflow.getConditions(commandKey))) {
+ if (!verifyConditions || verifyConditionsQuietly(review, context, workflow.getConditions(commandKey))) {
result.add(entry.getValue());
}
completeProjectSettings(context);
- Preconditions.checkState(verifyConditions(review, context, workflow.getConditions(commandKey)), "Conditions are not respected");
+ verifyConditions(review, context, workflow.getConditions(commandKey));
Map<String, String> immutableParameters = ImmutableMap.copyOf(parameters);
// TODO notify listeners
}
- private boolean verifyConditions(@Nullable Review review, WorkflowContext context, List<Condition> conditions) {
+ private boolean verifyConditionsQuietly(@Nullable Review review, WorkflowContext context, List<Condition> conditions) {
+ for (Condition condition : conditions) {
+ if (!condition.doVerify(review, context)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private void verifyConditions(@Nullable Review review, WorkflowContext context, List<Condition> conditions) {
for (Condition condition : conditions) {
if (!condition.doVerify(review, context)) {
- return false;
+ throw new IllegalStateException("Condition is not respected: " + condition.toString());
}
}
- return true;
}
private void completeProjectSettings(DefaultWorkflowContext context) {
Settings settings = context.getProjectSettings();
return settings.hasKey(getPropertyKey()) || settings.getDefaultValue(getPropertyKey()) != null;
}
+
+ public String toString() {
+ return "Property " + getPropertyKey() + " must be set";
+ }
}
@Test
public void execute_fail_if_conditions_dont_pass() {
thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Conditions are not respected");
+ thrown.expectMessage("Condition is not respected: Property foo must be set");
Workflow workflow = new Workflow();
workflow.addCommand("resolve");
#
def render_error(exception, status=500)
- message = exception.respond_to?('message') ? Api::Utils.exception_message(exception) : exception.to_s
+ message = exception.respond_to?('message') ? Api::Utils.exception_message(exception, :backtrace => true) : exception.to_s
java_facade.logError("Fail to render: #{request.url}\n#{message}") if status==500
respond_to do |format|
format.json { render :json => error_to_json(status, message), :status => status }
def render_error(error)
# Ruby on Rails has a single logger "rails", so it's not possible to distinguish profiling logs
# from error logs. For this reason a standard SLF4J logger is used instead of logger.error().
- java_facade.logError("Fail to render: #{request.url}\n#{Api::Utils.exception_message(error)}")
+ java_facade.logError("Fail to render: #{request.url}\n#{Api::Utils.exception_message(error, :backtrace => true)}")
if request.xhr?
message = error.respond_to?('message') ? error.message : error.to_s
access_denied unless has_rights_to_modify?(@review.resource)
bad_request('Missing command') if params[:command].blank?
- RuleFailure.execute_command(params[:command], @review.violation, @review.resource.project, current_user, params)
+ error_message = nil
+ begin
+ RuleFailure.execute_command(params[:command], @review.violation, @review.resource.project, current_user, params)
+ rescue Exception => e
+ error_message=Api::Utils.exception_message(e, :backtrace => false)
+ end
@review.reload
- render :partial => "project_reviews/view"
+ render :partial => "project_reviews/view", :locals => {:review => @review, :error_message => error_message}
end
violation.create_review!(:user_id => current_user.id)
end
- # TODO remove parameters id and command from params
- RuleFailure.execute_command(params[:command], violation, violation.snapshot.root_snapshot.project, current_user, params)
+ # TODO remove parameters 'id' and 'command' from params
+ error_message = nil
+ begin
+ RuleFailure.execute_command(params[:command], violation, violation.snapshot.root_snapshot.project, current_user, params)
+ rescue Exception => e
+ error_message=Api::Utils.exception_message(e, :backtrace => false)
+ end
# reload data required for display
violation.reload
screens = violation.available_java_screens(current_user)
- render :partial => 'resource/violation', :locals => {:violation => violation, :review_screens => screens}
+ render :partial => 'resource/violation', :locals => {:violation => violation, :review_screens => screens, :error_message => error_message}
end
#
if params[:comment_id]
violation.review.edit_comment(current_user, params[:comment_id].to_i, params[:text])
else
- begin
- violation.review.create_comment({:user => current_user, :text => params[:text]}, params[:review_command_id])
- rescue Exception => e
- # the review command may throw an exception
- flash["review_error_#{violation.id}"] = e.clean_message
- end
+ violation.review.create_comment({:user => current_user, :text => params[:text]}, params[:review_command_id])
end
end
Java::OrgSonarServerUi::JRubyFacade.getInstance().getMessage(I18n.locale, key, default, params.to_java)
end
- def self.exception_message(exception)
- result = (exception.respond_to?(:message) ? "#{exception.message}\n" : "#{exception}\n")
- if exception.respond_to? :backtrace
- result << "\t" + exception.backtrace.join("\n\t") + "\n"
+ #
+ # Options :
+ # - backtrace: append backtrace if true. Default value is false.
+ #
+ def self.exception_message(exception, options={})
+ cause = exception
+ if exception.is_a?(NativeException) && exception.respond_to?(:cause)
+ cause = exception.cause
+ end
+ result = (cause.respond_to?(:message) ? "#{cause.message}\n" : "#{cause}\n")
+ if options[:backtrace]==true && cause.respond_to?(:backtrace)
+ result << "\t" + cause.backtrace.join("\n\t") + "\n"
end
result
end
<h2><%= message('reviews.review_number', :params => h(review.id.to_s)) -%> - <%= h(review.title) -%></h2>
</div>
- <% if flash[:review_error] %>
- <div id="review_error" class="error"><%= flash[:review_error] %> <a href="#" onclick="$('review_error').hide(); return false;"><%= message('reviews.hide_this_message') -%></a></div>
+ <% if defined?(error_message) && error_message %>
+ <div id="review_error" class="error"><%= h error_message -%> <a href="#" onclick="$('review_error').hide(); return false;"><%= message('reviews.hide_this_message') -%></a></div>
<% end %>
<%
end
%>
- <% if flash["review_error_#{violation.id}"] %>
- <div id="review_error_<%= violation.id -%>" class="error"><%= flash["review_error_#{violation.id}"] %> <a href="#" onclick="$('review_error_<%= violation.id -%>').hide(); return false;"><%= message('reviews.hide_this_message') -%></a></div>
- <% end %>
-
<% if current_user %>
<div class="vActions" id="vActions<%= violation.id -%>">
+ <% if defined?(error_message) && error_message %>
+ <div id="review_error_<%= violation.id -%>" class="error"><%= h error_message -%> <a href="#" onclick="$('review_error_<%= violation.id -%>').hide(); return false;"><%= message('reviews.hide_this_message') -%></a></div>
+ <% end %>
+
<%= link_to_function message('reviews.comment'), "sCF(#{violation.id})", :name => 'bComment', :class => 'link-action spacer-right' -%>
<% unless violation.review && violation.review.resolved? %>