PedramNavid / dbtpal

Neovim plugin for dbt
99 stars 10 forks source link

All commands failing: `attempt to compare number with nil` in `commands.lua` #20

Closed nic-avant closed 1 year ago

nic-avant commented 1 year ago

Hello,

I'm starting to work with dbt and I'm exicted to see some plugins for neovim - I went to try this out with the jaffle_shop tutorial through the dbt-fundamentals course but none of the commands are working. I'm not a super savvy neovim user - so lua error messages are not second-nature for me to read but here's what I can copy out of :messages

Error executing Lua callback: ~/.local/share/nvim/lazy/dbtpal/lua/dbtpal/commands.lua:24: attempt to compare number with nil
stack traceback:
    ~/.local/share/nvim/lazy/dbtpal/lua/dbtpal/commands.lua:24: in function 'build_path_args'
    ~/.local/share/nvim/lazy/dbtpal/lua/dbtpal/main.lua:65: in function 'run'
    ~/.local/share/nvim/lazy/dbtpal/lua/dbtpal/init.lua:33: in function <~/.local/share/nvim/lazy/dbtpal/lua/dbtpal/init.lua:33>

edited the paths just for readability

Relevant Info:

  1. dbt run and all that works from the terminal
  2. gf works
  3. neovim v 0.9.1
  4. dbt version 1.4.1

Thanks for working on this extension - looking forward to using it heavily!

nic-avant commented 1 year ago

I use LazyVim and I have this configured in ~/.config/nvim/lua/plugins/dbt.lua

return {
  {
    "PedramNavid/dbtpal",
    opts = function()
      local dbt = require("dbtpal")
      dbt.setup({
        -- Path to the dbt executable
        path_to_dbt = "dbt",

        -- Path to the dbt project, if blank, will auto-detect
        -- using currently open buffer for all sql,yml, and md files
        -- tried hard coding to my dbt-fundamentals project but it didn't work either
        path_to_dbt_project = "",

        -- Path to dbt profiles directory
        path_to_dbt_profiles_dir = vim.fn.expand("~/.dbt"),

        -- Search for ref/source files in macros and models folders
        extended_path_search = true,

        -- Prevent modifying sql files in target/(compiled|run) folders
        protect_compiled_files = true,
      })

      -- Setup key mappings

      vim.keymap.set("n", "<leader>drf", dbt.run)
      vim.keymap.set("n", "<leader>drp", dbt.run_all)
      vim.keymap.set("n", "<leader>dtf", dbt.test)
      vim.keymap.set("n", "<leader>dm", require("dbtpal.telescope").dbt_picker)

      -- Enable Telescope Extension
      require("telescope").load_extension("dbtpal")
    end,
    dependencies = { { "nvim-lua/plenary.nvim" }, { "nvim-telescope/telescope.nvim" } },
  },
}
PedramNavid commented 1 year ago

Hey! Thanks for finding a bug, I think I narrowed it down to an issue with grep, hopefully the update I just pushed solves that.

This is my first time trying it with Lazy.nvim but I think you might have to slightly update the code as follows:

return {
  {
    "PedramNavid/dbtpal",
    init = function()
      require("dbtpal").setup({
        -- Path to the dbt executable
        path_to_dbt = "dbt",
        path_to_dbt_project = "",

        -- NOTE: You may need to change this if your course has a custom profiles.yml in the project directory.
        path_to_dbt_profiles_dir = vim.fn.expand("~/.dbt"),

        extended_path_search = true,
        protect_compiled_files = true,
      })

      vim.keymap.set("n", "<leader>drf", require('dbtpal').run)
      vim.keymap.set("n", "<leader>drp", require('dbtpal').run_all)
      vim.keymap.set("n", "<leader>dtf", require('dbtpal').test)
      vim.keymap.set("n", "<leader>dm", require("dbtpal.telescope").dbt_picker)

      require("telescope").load_extension("dbtpal")
    end,
  },
}

Let me know if that works or if you're still having trouble.

nic-avant commented 1 year ago

It's attempting now! The new thing is that it's not auto-detecting my dbt project... I don't know if this would be related to the grep problem so if it isn't then we could open a new issue, but basically I have a repo with project structure like this:

❯ tree . -L 2
.
├── README.md
├── data
│   ├── jaffle_shop_customers.csv
│   ├── jaffle_shop_orders.csv
│   ├── main.db
│   └── stripe_payments.csv
├── doom
│   ├── README.md
│   ├── analyses
│   ├── dbt_packages
│   ├── dbt_project.yml
│   ├── logs
│   ├── macros
│   ├── models
│   ├── seeds
│   ├── snapshots
│   ├── target
│   └── tests
├── init_db.py
├── logs
│   └── dbt.log
└── requirements.txt

13 directories, 10 files

And if I open nvim in . or in ./doom then DbtRun I get this error:

dbt command failed: dbt --printer-width=10 run --select --profiles-dir v:null --project-dir v:null

Encountered an error:
Runtime Error
    fatal: Invalid --project-dir flag. Not a dbt project. Missing dbt_project.yml file

But I had assumed the plugin would detect the dbt_project.yml file in ./doom

PedramNavid commented 1 year ago

This is the same dbt-fundamentals project in your repo?

I opened nvim in ./doom like this

 DBTPAL_LOG_LEVEL=trace nvim models/staging/jaffle_shop/stg_customers.sql

then ran :DbtBuild It ran the command correctly (failed because I don't have the doom dbt profile but thats not the main issue)

Failed to run dbt command. Exit Code: 2

------------

dbt command failed: dbt --printer-width=10 --log-level=INFO build --profiles-dir /Users/pedram/.dbt --project-dir /Users/pedram/repos/dbt-fundamentals/doom

Can you try running using the trace log level and pasting everythign from messages after running :DbtBuild ?

Just to confirm, you did update :Lazy and pressing U?

nic-avant commented 1 year ago

So based on your error message I see that mine is different with --profiles-dir v:null but in my lazy config I have:


        path_to_dbt_profiles_dir = vim.fn.expand("~/.dbt"),

Lazy is updated - I do not think that is the problem

Opening nvim with the trace didn't actually give me anymore of a message - looks like the profiles-dir is not being set right in the config or something?

nic-avant commented 1 year ago

Just set the path_to_dbt_profiles_dir to the explicit full path to /Users/me/.dbt and got the same issue - so looks to be definitely that that variable isn't getting bubbled around to where it needs to be... Is this another Mac-related issue?

PedramNavid commented 1 year ago

Can you share the full config? Trace should’ve given you many more messages.

Make sure you’re using init, not opts, in your Lazy config too please

nic-avant commented 1 year ago

Well I changed opts to init and now we're in business!

I need to review LazyVim config I guess, I haven't used init in any of my additional plugins

Thank you for responding to this so fast!

PedramNavid commented 1 year ago

Thanks for reporting the bug! Feel free to keep the feature requests and issues coming.