{"record":{"id":"5445a72cd7f2851f","repo":"padrino/padrino-framework","slug":"the-email-name-is-already-defined","errorCode":null,"errorMessage":"The email '#{name}' is already defined","messagePattern":"The email '#(.+?)' is already defined","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"padrino-mailer/lib/padrino-mailer/base.rb","lineNumber":84,"sourceCode":"      # Defines a mailer object allowing the definition of various email\n      # messages that can be delivered.\n      #\n      # @param [Symbol] name\n      #   The name of this email message.\n      # @param [Proc] block\n      #   The message definition (i.e subject, to, from, locals).\n      #\n      # @example\n      #   email :birthday do |name, age|\n      #     subject \"Happy Birthday!\"\n      #     to      'john@fake.com'\n      #     from    'noreply@birthday.com'\n      #     locals  name: name, age: age\n      #     render 'birthday'\n      #   end\n      #\n      def email(name, &block)\n        raise \"The email '#{name}' is already defined\" if self.messages[name]\n        self.messages[name] = proc { |*attrs|\n          message = app.settings._padrino_mailer::Message.new(self.app)\n          message.mailer_name = mailer_name\n          message.message_name = name\n          message.defaults = self.defaults if self.defaults.any?\n          message.delivery_method(*delivery_settings)\n          message.instance_exec(*attrs, &block)\n          message\n        }\n      end\n      alias message email\n\n      # Defines the default attributes for a message in this mailer\n      # (including app-wide defaults).\n      #\n      # @param [Hash] attributes\n      #   The hash of message options to use as default.\n      #","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/padrino/padrino-framework/blob/167044f3d56b2bce12f943eb826fdb0b0ea94375/padrino-mailer/lib/padrino-mailer/base.rb#L66-L102","documentation":"In the padrino-mailer DSL, each email :name do ... end block stores a proc in the mailer's messages hash keyed by that name. The email method raises when messages already has an entry for the name, preventing a second block from silently overwriting the first message definition.","triggerScenarios":"Declaring two email :welcome blocks in the same mailer; copy-pasting a message block and forgetting to rename it; code paths that declare the same email name twice while the mailer class is being defined or reopened.","commonSituations":"Copy-paste of an existing message as a starting point for a new one; merge conflicts where both branches add a message with the same name; refactoring that re-runs mailer declarations without reloading the class cleanly.","solutions":["Rename the second email block so every message name inside the mailer is unique","If the intent was to replace a message, delete the old block instead of redefining it","Run SampleMailer.messages.keys in a console to list defined names and find the collision"],"exampleFix":"# before — two blocks named :welcome in one mailer\nemail :welcome do ... end\nemail :welcome do ... end\n\n# after\nemail :welcome do ... end\nemail :welcome_reminder do ... end","handlingStrategy":"validation","validationCode":"# before declaring a message programmatically\nraise ArgumentError, 'email :name already defined' if SomeMailer.messages.key?(name)","typeGuard":"def mailer_message_name_free?(mailer, name)\n  !mailer.messages.key?(name)\nend","tryCatchPattern":null,"preventionTips":["Give every email block a unique name within its mailer","Rename copy-pasted message blocks before saving","After merges, grep each mailer for duplicate email : declarations"],"tags":["padrino-mailer","dsl","duplicate-definition","email"],"backgroundTag":"duplicate-key-definition","analyzedSha":"167044f3d56b2bce12f943eb826fdb0b0ea94375","analyzedAt":"2026-08-23T12:41:41.049Z","schemaVersion":2},"datasetVersion":"2026-08-23T16:17:53.355Z"}