Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carbon::Email is no longer serializable #91

Closed
akadusei opened this issue Feb 14, 2024 · 1 comment · Fixed by #92
Closed

Carbon::Email is no longer serializable #91

akadusei opened this issue Feb 14, 2024 · 1 comment · Fixed by #92

Comments

@akadusei
Copy link
Contributor

akadusei commented Feb 14, 2024

I include JSON::Serializable in my emails to have them sent in the background with Mel. Since Carbon v0.5, I get a compile error:

Showing last frame. Use --error-trace for full trace.

There was a problem expanding macro 'macro_139862332317072'

Code in /path/to/.crenv/versions/1.11.2/share/crystal/src/json/from_json.cr:271:3

 271 | {% begin %}
       ^
Called macro defined in /path/to/.crenv/versions/1.11.2/share/crystal/src/json/from_json.cr:271:3

 271 | {% begin %}

Which expanded to:

 > 27 |         
 > 28 |           when "io"
 > 29 |             __temp_4884 = self[:io].new(pull)
                                            ^--
Error: wrong number of arguments for 'IO::ARGF#initialize' (given 1, expected 2)

#88 introduced @attachment instance variable in Carbon::Email, a named tuple with one of its members being an IO, which is not serializable.

Is it possible to get rid of the @attachment instance variable? Maybe redefine .attachment macro thus:

macro attachment(value)
    def attachments : Array(Carbon::Attachment)
      {% if @type.methods.map(&.name).includes?("attachments".id) %}
        previous_def | [value]
      {% else %}
        [value]
      {% end %}
    end
  end

Code above is not tested, so I'm not sure if it works. But I'm thinking along the same lines as the callbacks:

macro before_send
def before_send
{% if @type.methods.map(&.name).includes?(:before_send.id) %}
previous_def
{% else %}
super
{% end %}
{{ yield }}
end
end

Or is there a better way to handle emails with Mel that I'm missing?

@akadusei akadusei changed the title Carbon::Email no longer serializable Carbon::Email is no longer serializable Feb 14, 2024
@jwoertink
Copy link
Member

Ah, yeah. I think we can come up with a patch for this. What do you think @manveru ?

akadusei added a commit to akadusei/carbon that referenced this issue Feb 23, 2024
jwoertink pushed a commit that referenced this issue Feb 25, 2024
* Make emails serializable

Fixes <#91>.

* Ensure that an attachment cannot be added more than once to the same email

* Add back `attachments` argument to `.def_equals` call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants