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

Undefined macro 'symbol_expected_message' if mistake in migration rollback function #507

Closed
Jigsik opened this issue Oct 29, 2020 · 1 comment · Fixed by #524
Closed
Assignees
Labels
bug Something isn't working improve error experience Make errors nicer to deal with

Comments

@Jigsik
Copy link

Jigsik commented Oct 29, 2020

Describe the bug
I tried to run lucky db:migrate command with an error in migration and instead of seeing an error message what went wrong I saw a message:

Error: undefined macro variable 'symbol_expected_message'

To Reproduce
Steps to reproduce the behavior:

  1. Create migration
  2. Make error in rollback function

e.g.

# Invalid code
def rollback
    alter :cooperation_requests do
      remove description : String
    end
end

instead of

# Valid code
def rollback
    alter :cooperation_requests do
      remove :description
    end
end
  1. Run lucky db:migrate command
  2. See this error in console
jigs@jigs-VirtualBox:/project$ lucky db.migrate
Showing last frame. Use --error-trace for full trace.

In lib/avram/src/avram/migrator/alter_table_statement.cr:201:16

 201 | {% raise symbol_expected_message % {"remove", name} %}
                ^----------------------
Error: undefined macro variable 'symbol_expected_message'

Expected behavior
Macro should be defined and print appropriate error message in console.

Versions (please complete the following information):

  • Lucky version (check in shard.lock): 0.24.0
  • Crystal version (crystal --version): 0.35.1
  • OS: Ubuntu 20.10
@jwoertink jwoertink transferred this issue from luckyframework/lucky Oct 29, 2020
@jwoertink
Copy link
Member

Hey, good find! Looking back at this code, looks like it never worked as intended. That variable is defined here. Turns out, macro StringLiteral doesn't have the % method, and you can't call the macro level variable defined outside from inside a macro...

Instead, the symbol_expected_message should become a macro method that takes 2 arguments, and just interpolate the string instead.

I've moved this issue in to Avram since the fix will need to be done in this repo.

@jwoertink jwoertink added bug Something isn't working improve error experience Make errors nicer to deal with labels Oct 29, 2020
@matthewmcgarvey matthewmcgarvey self-assigned this Nov 10, 2020
@matthewmcgarvey matthewmcgarvey linked a pull request Nov 11, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working improve error experience Make errors nicer to deal with
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants