From e8df6c311fcf59bf23d31b9db2bb8fec9d78fbe7 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Mon, 17 Oct 2022 14:12:24 -0700 Subject: [PATCH] Simplify error reported by loading tree-sitter language definition Before: Error: Cannot load language definition: "javascript", ("/home/jostein/.emacs.d/tree-sitter/libtree-sitter-javascript: cannot open shared object file: No such file or directory" "/home/jostein/.emacs.d/tree-sitter/libtree-sitter-javascript.so: cannot open shared object file: No such file or directory" "libtree-sitter-javascript: cannot open shared object file: No such file or directory" "libtree-sitter-javascript.so: cannot open shared object file: No such file or directory") After: (treesit-load-language-error not-found ("libtree-sitter-z.so" "libtree-sitter-z.dylib") "No such file or directory") * src/treesit.c (treesit_load_language): Add base_candidates, remove error_list, report base_candidates rather than error_list. --- src/treesit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/treesit.c b/src/treesit.c index 90a1249ba8d..036411865d3 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -512,6 +512,8 @@ treesit_load_language (Lisp_Object language_symbol, /* First push just the filenames to the candidate list, which will make dynlib_open look under standard system load paths. */ treesit_load_language_push_for_each_suffix (lib_base_name, &path_candidates); + /* This is used for reporting errors (i.e., just filenames). */ + Lisp_Object base_candidates = path_candidates; /* Then push ~/.emacs.d/tree-sitter paths. */ Lisp_Object lib_name = Fexpand_file_name (concat2 (build_string ("tree-sitter/"), lib_base_name), @@ -531,7 +533,6 @@ treesit_load_language (Lisp_Object language_symbol, fail. */ dynlib_handle_ptr handle; char const *error; - Lisp_Object error_list = Qnil; for (Lisp_Object tail = path_candidates; !NILP (tail); tail = XCDR (tail)) { @@ -541,13 +542,12 @@ treesit_load_language (Lisp_Object language_symbol, error = dynlib_error (); if (error == NULL) break; - else - error_list = Fcons (build_string (error), error_list); } if (error != NULL) { *signal_symbol = Qtreesit_load_language_error; - *signal_data = Fcons (Qnot_found, Fnreverse (error_list)); + *signal_data = list3 (Qnot_found, base_candidates, + build_string ("No such file or directory")); return NULL; } -- 2.39.2