FIX: Don't log an error to logster if a topic could not be updated.

FIX: Don’t log an error to logster if a topic could not be updated.

If for some reason an update did not go through (for example, concurrently updating the same topic twice), we were logging something like:

create_errors_json called with unrecognized type: #<Topic

This happened because we knew an error occurred but the active record object had no errors attached.

This patch fixes the issue by attaching a proper error message in the event that this happens.

diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index e0ecde6..2d93468 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -372,6 +372,10 @@ class TopicsController < ApplicationController
     if changes.length > 0
       first_post = topic.ordered_posts.first
       success =, topic).revise!(current_user, changes, validate_post: false)
+      if !success && topic.errors.blank?
+        topic.errors.add(:base, :unable_to_update)
+      end
     # this is used to return the title to the client as it may have been changed by "TextCleaner"
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 23f492a..004f511 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -534,6 +534,7 @@ en:
               no_user_selected: "You must select a valid user."
               reply_by_email_disabled: "Reply by email has been disabled."
               target_user_not_found: "One of the users you are sending this message to could not be found."
+              unable_to_update: "There was an error updating that topic."
               invalid: "is invalid. URL should include http:// or https://."
               invalid_category: "can't be edited in this category."
diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb
index e48a2f9..ebb2b90 100644
--- a/spec/requests/topics_controller_spec.rb
+++ b/spec/requests/topics_controller_spec.rb
@@ -956,6 +956,16 @@ RSpec.describe TopicsController do
           expect(::JSON.parse(response.body)['basic_topic']).to be_present
+        it "throws an error if it could not be saved" do
+          PostRevisor.any_instance.stubs(:should_revise?).returns(false)
+          put "/t/#{topic.slug}/#{}.json", params: { title: "brand new title" }
+          expect(response.status).to eq(422)
+          expect(response.parsed_body['errors'].first).to eq(
+            I18n.t("activerecord.errors.models.topic.attributes.base.unable_to_update")
+          )
+        end
         it "can update a topic to an uncategorized topic" do
           topic.update!(category: Fabricate(:category))

GitHub sha: 13f2723d