jeaye / color_coded

A vim plugin for libclang-based highlighting of C, C++, ObjC
MIT License
870 stars 53 forks source link

Print specific errors when color_coded.so fails to load #170

Open saristov opened 6 years ago

saristov commented 6 years ago

I recently had an issue with my build environment, which lead to badly build color_coded.so library which failed to load. While the issue itself was more or less trivial to fix after the exact cause of the problem was found, the default plugin behavior was not friendly, all that was given was "color_coded unavailable: you need to compile it (see README.md)".

I suggest the pcall invocation to be changed to include the error message and the message printed on failure. I made "quick and dirty" local change, but I believe, it could be better. My changes are:

diff --git a/autoload/color_coded.vim b/autoload/color_coded.vim
index 02e6359..bf6f62e 100644
--- a/autoload/color_coded.vim
+++ b/autoload/color_coded.vim
@@ -42,13 +42,14 @@ function! color_coded#setup()
   " Try to get the lua binding working
   lua << EOF
     package.cpath = vim.eval("$VIMHOME") .. "/color_coded.so"
-    local loaded = pcall(require, "color_coded")
+    local loaded, err = pcall(require, "color_coded")
     if not loaded then
       vim.command('echohl WarningMsg | ' ..
             'echomsg "color_coded unavailable: you need to compile it ' ..
-            '(see README.md)" | ' ..
+            '(see README.md) ' .. package.cpath .. '" | ' ..
             'echohl None')
       vim.command("let s:color_coded_valid = 0")
+      print(err)
       return
     else
       local version = color_coded_api_version()
jeaye commented 6 years ago

Thanks for the detailed ticket! I'm glad you were able to sort out your issue with a minimal change to the code. I think, in general, this is a pretty good proposed change, but I think we can redirect the error output to a color_coded.log, perhaps. Are you up for making a PR with the above changes, except just printing the error output to a file?

From there, we'll just need to update the readme to mention the error log file. You could include that in the PR or I could do it.