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

custom ebuku-database-path issue on Windows #31

Closed
edzhangsy opened this issue Apr 12, 2024 · 10 comments
Closed

custom ebuku-database-path issue on Windows #31

edzhangsy opened this issue Apr 12, 2024 · 10 comments

Comments

@edzhangsy
Copy link

Hi, I am trying ebuku on Windows.
I put the absolute path for my database file in the ebuku-database-path variable with
(setq ebuku-database-path "C:/Users/uname/.local/share/buku/bookmarks.db")
But then I get the error message "invalid string for collation: Invalid argument".

The path is valid, and when I call the buku --db C:/Users/uname/.local/share/buku/bookmarks.db --print, it works fine.

Also, when I try some address alternatives like
(setq ebuku-database-path "~/.local/share/buku/bookmarks.db")
There will be new directory created under the working directory, like
D:\pwd\~\.local\share\buku\bookmarks.db

I guess that's because buku will create a new db if you provide some valid path.
And my suspicion is that the substitute-in-file-name function is the cause, maybe this function don't handle the Windows path properly.

@flexibeast
Copy link
Owner

Hmm. The error invalid string for collation: Invalid argument comes from sysdep.c:

#ifdef WINDOWSNT
int
str_collate (Lisp_Object s1, Lisp_Object s2,
             Lisp_Object locale, Lisp_Object ignore_case)
{

  char *loc = STRINGP (locale) ? SSDATA (locale) : NULL;
  int res, err = errno;

  errno = 0;
  res = w32_compare_strings (SSDATA (s1), SSDATA (s2), loc, !NILP (ignore_case));
  if (errno)
    error ("Invalid string for collation: %s", strerror (errno));

  errno = err;
  return res;
}
#endif  /* WINDOWSNT */

So we need to check your locale settings, and in particular, the value of the LC_COLLATE environment variable.

How are you running Emacs - natively, or via WSL?

i'm not a Windows user myself, but if you're running Emacs natively, you could perhaps try either starting PowerShell and running Get-WinSystemLocale, or starting a command prompt and running systeminfo.

If you're running Emacs via WSL, please run locale from a terminal.

At any rate, please share all the output here.

@edzhangsy
Copy link
Author

Hi, thank you for your timely reply.
I am using Emacs natively on Windows.
And the output for the Get-WinSystemLocale is

LCID             Name             DisplayName
----             ----             -----------
2052             zh-CN            中文(中国)

I am using Chinese as my primary language.
Also, I set the LANG environment variable as zh_CN.UTF-8 and LC_ALL as C
I am new to Emacs, could you tell me also how do you debug and find the troublesome str_collate function.
Are you grepping the error message in the code base?

@flexibeast
Copy link
Owner

Are you grepping the error message in the code base?

Yes, i cloned the Git repo: https://savannah.gnu.org/projects/emacs

Also, I set the LANG environment variable as zh_CN.UTF-8 and LC_ALL as C.

Okay. Usually LC_ALL includes LC_COLLATE, but i don't know whether this is true on Windows. As a test, what happens if you instead set LC_ALL to zh_CN.UTF-8? Does that make any difference?

@edzhangsy
Copy link
Author

I made the change but the error message persists.
I also changed the ebuku-buku-path variable, which works fine.
(setq ebuku-buku-path "C:/Users/uname/.local/bin/buku.exe")
I wounder what is the difference to cause the issue.
I tried several strings.
The C:/Users/name/.local/bin/bookmarks.ed will cause the error.
The /Users/name/.local/bin/bookmarks.db will cause the error.
The ~/Users/name/.local/bin/bookmarks.db is accepted.
In this case, it will concat this address to the address of the file I am editing and create a new database.
For example, C:/Users/name/.emacs.d/~/Users/name/.local/bin/bookmarks.db

@flexibeast
Copy link
Owner

Thanks for checking that. Hm. Could you please enable debug-on-error (M-x toggle-debug-on-error), and share the trace output that comes up when you do the thing that results in the "Invalid string for collation" error? There are only a few uses of ebuku-database-path in the code, and the trace should help find which one is causing the error.

(i don't know if the problem is an incorrect assumption in my code, or in Emacs' code, as you suggested might be the case.)

@edzhangsy
Copy link
Author

The full trace is here
I use the C:/Users/name/.local/bin/bookmarks.db as the path.

Debugger entered--Lisp error: (args-out-of-range "1884. Welcome to Comprehensive Rust 🦀 - Comprehens..." 15862 15893)
  match-string(1 "1884. Welcome to Comprehensive Rust 🦀 - Comprehensive Rust 🦀")
  ebuku--search-helper("--print" "[all]" "-1000" "")
  ebuku-show-all()
  ebuku()
  funcall-interactively(ebuku)
  command-execute(ebuku record)
  execute-extended-command(nil "ebuku" "ebuku")
  funcall-interactively(execute-extended-command nil "ebuku" "ebuku")
  command-execute(execute-extended-command)

So the path utility is functional and works well.
It seems there are some error happened displaying the bookmarks.
I removed the crab emoji and that bookmark entry don't cause trouble.
But the emoji from another entry is causing the same issue
It seems it's the emoji that cause the trouble.
When I copy the trace to the github issue, the crab emoji is correctly displayed above, so the code for emoji is correct.

image
image

@flexibeast
Copy link
Owner

Thanks for that.

However, i'm a bit confused. In your original comment, you wrote that the error message was "invalid string for collation: Invalid argument"; here, however, the trace shows the error message to be "(args-out-of-range "1884. Welcome to Comprehensive Rust 🦀 - Comprehens..." 15862 15893)"

Are you now unable to reproduce the circumstances that resulted in the "Invalid string for collation" message?

i can certainly work on the issue with emojis, and that issue might actually be related to the "Invalid string for collation" issue, but it would help me to know whether the latter issue still exists, or if it was actually fixed by setting LC_ALL to zh_CN.UTF-8, which then exposed the emojis issue.

If you can no longer reproduce the "Invalid string for collation" issue with your system, can you please let me know if it returns if you change LC_ALL back to C?

@edzhangsy
Copy link
Author

Thank you for your efforts.
I turn off the debug toggle and changed my LC_ALL to zh_CN.UTF-8.
Ebuku can find the db now.
It seems the "Invalid string for collation" problem is fixed by changing the LC_ALL.
Last time I told you that changing LC_ALL is not working, maybe that's because I forgot to restart.
Windows's environment variable will take effect after restart.
Right now when I invoke the ebuku command, the "args out of range" problems appears.

@flexibeast
Copy link
Owner

Ah, okay - no worries, i sometimes forget to that myself, so i understand. :-)

Okay, i'll work on the emoji problem; i'll open a new issue for it, and then close this one.

@flexibeast
Copy link
Owner

Opened new issue as #32, closing this one.

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

No branches or pull requests

2 participants