gnebbia / kb

A minimalist command line knowledge base manager
GNU General Public License v3.0
3.17k stars 104 forks source link

kb grep "IndexError: list index out of range" #83

Closed ArchWizard56 closed 3 years ago

ArchWizard56 commented 3 years ago

Hi! It's me again. I've been working on migrating my notes into kb, and I ran across this error. I'm planning on looking into it a bit, but I wanted to open the issue first.

Expected Behavior

kb ought to display a list of artifacts containing the word, as shown in https://github.com/gnebbia/kb#grep-through-the-knowledge-base

Actual Behavior

kb throws an IndexError. This only seems to occur if the grep successfully matches an artifact. Nothing seems to change if I use the -v flag. It works if I use the -m flag to show the matching lines instead of the artifacts.

Ghostbin with full error: https://ghostbin.co/paste/tyqqos

Steps to Reproduce the Problem

  1. Run kb grep with any word that exists in the knowledge base.

Specifications

xscode-auto-reply[bot] commented 3 years ago

Thanks for opening a new issue. The team has been notified and will review it as soon as possible. For urgent issues and priority support, visit https://xscode.com/gnebbia/kb

gnebbia commented 3 years ago

Dear Sir, I am unable to reproduce the error, can we try to isolate the issue by being more specific about when this throws an exception?

hexiyou commented 3 years ago

I had the same problem on Cygwin: image

gnebbia commented 3 years ago

Dear Sir, this looks a lot like an older version bug, could you try to uninstall kb and try to re-install the latest version? Thanks a lot

gnebbia commented 3 years ago

Can you let me know if the bug persists on the latest version?

hexiyou commented 3 years ago

Can you let me know if the bug persists on the latest version?

I already uninstall local version and reinstall from github repository,then i got the same problem.

image


image

gnebbia commented 3 years ago

How can i reproduce this? Could you send me some articles from your knowledge base? so that I can inspect them? Probaby related to some UTF-8 char? Did you try deleting your knowledge base and trying to import it again?

You can do something like: kb add ./myelectornicsstuff/ --category "electronics" kb add ./cheatsheet/ --category "cheatsheet" kb add ./protocol/ --category "protocol" kb add ./config/ --category "config"

To quickly reimport your artcles from text files. Could you do that test for me? Because I am not able to reproduce the issue. Thanks a lot!

gnebbia commented 3 years ago

Can you let me know if the bug persists on the latest version?

I already uninstall local version and reinstall from github repository,then i got the same problem.

image

image

Ok, I think I was able to track the issue. I think that updating kb was not enough since this is related to how kb used to store in previous versions artifacts.

Hence, I htink you should basically delete your knowledge base and re-import it.

Unluckily these were issues of previous versions of kb on how data was stored. These issues are fixed with the latest version.

prokaryont commented 3 years ago

Hi,

i found that the problem (also?) occurs when the title of an artifact contains spaces. Reproducing the error:

kb add -t 'win style name' -b win
kb grep win

01_space_title_error

The cause seems that get_filename_parts_wo_prefix() parses the title of the artifacts incorrectly.

02_incorrectly_parsed_title

Instead of the expected two element tuple of the form [(category, title)], the returned list contains a tuple ('default', 'win', 'style', 'name'). Later, when results are fetches with db_get_artifacts_by_filter(), the category parameter is default/win/style. The call returns an empty list and when the result is indexed the IndexError is raised.

04_incorrect_category_parameter

Quick fix for the users until the issue is resolved: remove spaces/backslashes from your artifacts' titles.

For parsing the path correctly, the pathlib module might help. I'm not sure why backslashes are removed. Is this done to ensure windows compatibility?