aosabook/500lines · error · Exception

%s (index|query|grep) index_dir ...

Error message

%s (index|query|grep) index_dir ...

What it means

Error "%s (index|query|grep) index_dir ..." thrown in aosabook/500lines.

Source

Thrown at incomplete/search-engine/index.py:260

        except Exception:          # The file might e.g. no longer exist.
            traceback.print_exc()
def main(argv):
    # Eliminate the most common English words from queries and indices.
    stopwords = 'the of and to a in it is was that i for on you he be'.split()

    if argv[1] == 'index':
        build_index(index_path=Path(argv[2]), corpus_path=Path(argv[3]),
                    postings_filters=[discard_long_nonsense_words_filter,
                                      make_stopwords_filter(stopwords),
                                      case_insensitive_filter])
    elif argv[1] == 'query':
        search_ui(Path(argv[2]), [term for term in argv[3:]
                                  if term not in stopwords])
    elif argv[1] == 'grep':
        grep(Path(argv[2]), [term for term in argv[3:]
                             if term not in stopwords])
    else:
        raise Exception("%s (index|query|grep) index_dir ..." % (argv[0]))

if __name__ == '__main__':
    main(sys.argv)

View on GitHub (pinned to fba689d101)

Solutions

  1. Invoke the script with one of the supported subcommands: index, query, or grep.
  2. Provide the index_dir argument after the subcommand.
  3. Check sys.argv handling if wrapping this script so the subcommand is argv[1].

Example fix

python index.py index my_index_dir/  # or: python index.py query my_index_dir/ term1 term2

When it happens

Trigger: Thrown at incomplete/search-engine/index.py:260 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of aosabook/500lines@fba689d101 (2026-08-13). Data as JSON: /api/errors/a1627facd7011c23. Report an issue: GitHub.