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

Basic config on Windows 10 raises a fatal error. #88

Closed
ChristianLemer opened this issue Feb 1, 2023 · 26 comments
Closed

Basic config on Windows 10 raises a fatal error. #88

ChristianLemer opened this issue Feb 1, 2023 · 26 comments
Labels
bug Something isn't working os: windows

Comments

@ChristianLemer
Copy link

🐛 Describe the bug

When I try to use the basic config on Windows 10:

require("obsidian").setup({
  dir = "~/my/local/obsidian/repo/",
  completion = {
    nvim_cmp = true,
  }
})

I get the following error message:

E5108: Error executing lua ...site\pack\packer\start\plenary.nvim/lua/plenary/path.lua:497: We couldn't mkdir: C:\Users\myhome\AppData\Local\nvim\lua\C:/Users/myhome/my/local/obsidian/repo/
stack traceback:
	[C]: in function 'error'
	...site\pack\packer\start\plenary.nvim/lua/plenary/path.lua:497: in function 'mkdir'
	...te\pack\packer\start\obsidian.nvim/lua/obsidian/init.lua:54: in function 'setup'
	[string ":source (no file)"]:601: in main chunk

Obviously, there is a problem with the concatenation of a Windows and a Unix path.

It could be a bug in my config, but I couldn't find the answer in the manual or online.

Thanks for advice on this.

Versions

1.6.1

@ChristianLemer ChristianLemer added the bug Something isn't working label Feb 1, 2023
@epwalsh
Copy link
Owner

epwalsh commented Feb 1, 2023

Have you tried specifying the dir in your setup with a Windows-style path?

@ChristianLemer
Copy link
Author

Yes, I did.

The path seems to be understood. The tilde expansion works as expected (see the end of the path)

It appears that the config directory path is prepended to the path using the windows-style notation.

C:\Users\myhome\AppData\Local\nvim\lua\C:/Users/myhome/my/local/obsidian/repo/

@epwalsh
Copy link
Owner

epwalsh commented Feb 1, 2023

Hmm, weird. I don't have access to a Windows comp so you may have to help me debug. Could you these lines right before this line and tell me what it prints?

  print("A:", tostring(opts.dir))
  print("B:", vim.fs.normalize(tostring(opts.dir)))
  print("C:", tostring(Path:new(vim.fs.normalize(tostring(opts.dir)))))

@ChristianLemer
Copy link
Author

All the same...

A:  C:/Users/myhome/my/local/obsidian/repo/
B:  C:/Users/myhome/my/local/obsidian/repo/
C:  C:/Users/myhome/my/local/obsidian/repo/

@epwalsh
Copy link
Owner

epwalsh commented Feb 1, 2023

It seems like a bug with Plenary's Path:mkdir() then.. I've opened an issue there: nvim-lua/plenary.nvim#456

@ChristianLemer
Copy link
Author

Thanks for your quick follow-up on this.

@0xbs0d
Copy link

0xbs0d commented Mar 9, 2023

I just tried to configure this for myself and it works fine. I added dir as dir = "c:\\users\\my-name\\iCloudDrive\\iCloud~md~obsidian\\",

edit: Windows 11, lunarvim on neovim 0.8.0 and iCloud for syncing Obsidian with my other devices.

@azinsharaf
Copy link

yes, the dir path on windows should be like that.
dir = "C:\\Users\\asharaf\\iCloudDrive\\iCloud~md~obsidian\\Azin-Obsidian",

@epwalsh
Copy link
Owner

epwalsh commented Nov 23, 2023

Sounds like this was resolved. If anyone is still having this issue I'll reopen.

@epwalsh epwalsh closed this as completed Nov 23, 2023
@777uliahshafar
Copy link

Hello everyone, I am also Window user, but the use of solution above did not work for me. Is there any solution? Thank you.

@nevenoomo
Copy link

nevenoomo commented Jan 26, 2024

I am also getting a similar error whenever I call "ObsidianToday" for a non-existing daily note:

Error executing Lua callback: ...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/path.lua:505: We couldn't mkdir: C:\Users\user\OneDrive\Documents\Obsidian Vaults\Main Workspace\C:/Users/user/OneDrive/Documents/Obsidian Vaults/Main Workspace
stack traceback:
        [C]: in function 'error'
        ...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/path.lua:505: in function 'mkdir'
        .../nvim-data/lazy/obsidian.nvim/lua/obsidian/templates.lua:65: in function 'clone_template'
        ...cal/nvim-data/lazy/obsidian.nvim/lua/obsidian/client.lua:876: in function 'daily'
        ...-data/lazy/obsidian.nvim/lua/obsidian/commands/today.lua:17: in function 'func'
        ...m-data/lazy/obsidian.nvim/lua/obsidian/commands/init.lua:63: in function <...m-data/lazy/obsidian.nvim/lua/obsidian/commands/init.lua:62>

Edit: seems to only occur when a template is used with daily notes.

@epwalsh
Copy link
Owner

epwalsh commented Jan 26, 2024

@nevenoomo can you post your config?

@nevenoomo
Copy link

Here you go:

return {
	"epwalsh/obsidian.nvim",
	version = "*", -- recommended, use latest release instead of latest commit
	lazy = true,
	ft = "markdown",
	cmd = {
		"ObsidianOpen",
		"ObsidianNew",
		"ObsidianQuickSwitch",
		"ObsidianFollowLink",
		"ObsidianBacklinks",
		"ObsidianTags",
		"ObsidianToday",
		"ObsidianYesterday",
		"ObsidianTomorrow",
		"ObsidianTemplate",
		"ObsidianSearch",
		"ObsidianLink",
		"ObsidianLinkNew",
		"ObsidianWorkspace",
		"ObsidianPasteImg",
		"ObsidianRename",
	},
	-- Replace the above line with this if you only want to load obsidian.nvim for markdown files in your vault:
	-- event = {
	--   -- If you want to use the home shortcut '~' here you need to call 'vim.fn.expand'.
	--   -- E.g. "BufReadPre " .. vim.fn.expand "~" .. "/my-vault/**.md"
	--   "BufReadPre path/to/my-vault/**.md",
	--   "BufNewFile path/to/my-vault/**.md",
	-- },
	dependencies = {
		-- Required.
		"nvim-lua/plenary.nvim",
	},
	opts = {
		workspaces = {
			{
				name = "main",
				path = "~/OneDrive/Documents/Obsidian Vaults/Main Workspace",
			},
		},
		daily_notes = {
			folder = "📆Journals",
			template = "New Day",
		},
		templates = {
			subdir = "📜Templates",
			-- A map for custom variables, the key should be the variable and the value a function
			substitutions = {},
		},
		completion = {
			-- Set to false to disable completion.
			nvim_cmp = true,

			-- Trigger completion at 2 chars.
			min_chars = 2,

			-- Where to put new notes created from completion. Valid options are
			--  * "current_dir" - put new notes in same directory as the current buffer.
			--  * "notes_subdir" - put new notes in the default notes subdirectory.
			new_notes_location = "current_dir",

			-- Control how wiki links are completed with these (mutually exclusive) options:
			--
			-- 1. Whether to add the note ID during completion.
			-- E.g. "[[Foo" completes to "[[foo|Foo]]" assuming "foo" is the ID of the note.
			-- Mutually exclusive with 'prepend_note_path' and 'use_path_only'.
			prepend_note_id = true,
			-- 2. Whether to add the note path during completion.
			-- E.g. "[[Foo" completes to "[[notes/foo|Foo]]" assuming "notes/foo.md" is the path of the note.
			-- Mutually exclusive with 'prepend_note_id' and 'use_path_only'.
			prepend_note_path = false,
			-- 3. Whether to only use paths during completion.
			-- E.g. "[[Foo" completes to "[[notes/foo]]" assuming "notes/foo.md" is the path of the note.
			-- Mutually exclusive with 'prepend_note_id' and 'prepend_note_path'.
			use_path_only = false,
		},
	},
	config = function(_, opts)
		require("obsidian").setup(opts)

		vim.o.conceallevel = 2
	end
}

Important note: I have tried all the different variations of the workspace.path, including absolute path, forward and back slashes, etc.

I have also tried different template referencing options, like "New Day", "New Day.md", "📜Templates/New Day", and other permutations.

@epwalsh
Copy link
Owner

epwalsh commented Jan 26, 2024

Thanks @nevenoomo, I don't see any issues with your config. Can you run this from a note buffer and post the output:

:lua vim.print(require("obsidian").get_client():daily_note_path(os.time()))

I suspect the issue comes from this method, so that will confirm it for me.

@nevenoomo
Copy link

I am not sure that's the problem, the path seems correct, even with the mixed slashes:

{
  _sep = "\\",
  filename = "C:/Users/user/OneDrive/Documents/Obsidian Vaults/Main Workspace\\📆Journals\\2024-01-26.md",
  <metatable> = {
    __concat = <function 1>,
    __div = <function 2>,
    __index = <function 3>,
    __tostring = <function 4>,
    _fs_filename = <function 5>,
    _read = <function 6>,
    _read_async = <function 7>,
    _split = <function 8>,
    _st_mode = <function 9>,
    _stat = <function 10>,
    absolute = <function 11>,
    close = <function 12>,
    copy = <function 13>,
    exists = <function 14>,
    expand = <function 15>,
    find_upwards = <function 16>,
    head = <function 17>,
    is_absolute = <function 18>,
    is_dir = <function 19>,
    is_file = <function 20>,
    is_path = <function 21>,
    iter = <function 22>,
    joinpath = <function 23>,
    make_relative = <function 24>,
    mkdir = <function 25>,
    new = <function 26>,
    normalize = <function 27>,
    open = <function 28>,
    parent = <function 29>,
    parents = <function 30>,
    path = {
      S_IF = {
        DIR = 16384,
        REG = 32768
      },
      home = "C:\\Users\\user",
      root = <function 31>,
      sep = "\\"
    },
    read = <function 32>,
    readbyterange = <function 33>,
    readlines = <function 34>,
    rename = <function 35>,
    rm = <function 36>,
    rmdir = <function 37>,
    shorten = <function 38>,
    tail = <function 39>,
    touch = <function 40>,
    write = <function 41>
  }
}

@epwalsh
Copy link
Owner

epwalsh commented Jan 26, 2024

Ah, okay, maybe the issue is from converting that Path to a string and then back. Can you try on this branch: #349 (epwalsh/template-fix-on-windows)?

@nevenoomo
Copy link

Unfortunately, it does not seem to solve the problem:

Error executing Lua callback: ...l/nvim-data/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: Vim:Error executing Lua callback: ...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/path.lua:505: We couldn't mkdir: C:\Users\user\AppData\Local\nvim\C:/Users/user/OneDrive/Documents/Obsidian Vaults/Main Workspace
stack traceback:
        [C]: in function 'error'
        ...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/path.lua:505: in function 'mkdir'
        .../nvim-data/lazy/obsidian.nvim/lua/obsidian/templates.lua:65: in function 'clone_template'
        ...cal/nvim-data/lazy/obsidian.nvim/lua/obsidian/client.lua:969: in function 'daily'
        ...-data/lazy/obsidian.nvim/lua/obsidian/commands/today.lua:17: in function 'func'
        ...m-data/lazy/obsidian.nvim/lua/obsidian/commands/init.lua:64: in function <...m-data/lazy/obsidian.nvim/lua/obsidian/commands/init.lua:63>
        [C]: in function 'cmd'
        ...l/nvim-data/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: in function <...l/nvim-data/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>
stack traceback:
        [C]: in function 'cmd'
        ...l/nvim-data/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: in function <...l/nvim-data/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>

Notice, that the erroneous path has changed. It seems to be set to (pwd + templateDir).parent (I was launching neovim from nvim directory this time).

@epwalsh
Copy link
Owner

epwalsh commented Jan 26, 2024

So maybe Path:parent is wrong? What's the output of this:

:lua vim.print(require("obsidian").get_client():daily_note_path(os.time()):parent())

@nevenoomo
Copy link

That seems to be the case:

{
  _sep = "\\",
  filename = "C:\\Users\\user\\AppData\\Local\\nvim\\C:/Users/user/OneDrive/Documents/Obsidian Vaults/Main Workspace\\📆Journals",
  <metatable> = {
    __concat = <function 1>,
    __div = <function 2>,
    __index = <function 3>,
    __tostring = <function 4>,
    _fs_filename = <function 5>,
    _read = <function 6>,
    _read_async = <function 7>,
    _split = <function 8>,
    _st_mode = <function 9>,
    _stat = <function 10>,
    absolute = <function 11>,
    close = <function 12>,
    copy = <function 13>,
    exists = <function 14>,
    expand = <function 15>,
    find_upwards = <function 16>,
    head = <function 17>,
    is_absolute = <function 18>,
    is_dir = <function 19>,
    is_file = <function 20>,
    is_path = <function 21>,
    iter = <function 22>,
    joinpath = <function 23>,
    make_relative = <function 24>,
    mkdir = <function 25>,
    new = <function 26>,
    normalize = <function 27>,
    open = <function 28>,
    parent = <function 29>,
    parents = <function 30>,
    path = {
      S_IF = {
        DIR = 16384,
        REG = 32768
      },
      home = "C:\\Users\\user",
      root = <function 31>,
      sep = "\\"
    },
    read = <function 32>,
    readbyterange = <function 33>,
    readlines = <function 34>,
    rename = <function 35>,
    rm = <function 36>,
    rmdir = <function 37>,
    shorten = <function 38>,
    tail = <function 39>,
    touch = <function 40>,
    write = <function 41>
  }
}

@epwalsh
Copy link
Owner

epwalsh commented Jan 26, 2024

Looks like this bug was already reported in nvim-lua/plenary.nvim#489

@nevenoomo
Copy link

Great! Thanks, @epwalsh!

@epwalsh
Copy link
Owner

epwalsh commented Jan 26, 2024

I added a work-around in #349. Can you try that again?

@nevenoomo
Copy link

nevenoomo commented Jan 26, 2024

It works!

@epwalsh
Copy link
Owner

epwalsh commented Jan 26, 2024

@nevenoomo, I'll merge and release.

@nevenoomo
Copy link

Great work, @epwalsh!

@777uliahshafar

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working os: windows
Projects
None yet
Development

No branches or pull requests

6 participants