Expects a runtime error to return even though it does so

Hey all,

I believe I got a similar error to this months ago, however, this one has been puzzling me for a while now.

Whenever I test my code using the codecrafter CLI i get a “expected runtime error (exit code 70), got exit code -1” when it clearly does return a runtime error

Here are my code snippets:

[main.cpp]

   } else if(command == "run") {
        string file_contents = read_file_contents(argv[2]);

        try { // checks for any unterminated comment blocks
            Scanner scan(file_contents);
        } catch (invalid_argument& err) {
            cerr << err.what();
            return 65;
        }

        Scanner scanner(file_contents);
        if(scanner.getErrStatus())
            return 65;

        Parser parser(scanner.getTokens());
        Interpreter interpreter;

        try {
            interpreter.interpret(parser.parseStmt());
        } catch (runtime_error& err) {
            cerr << err.what();
            return 65;
        }

[Interpreter.cpp]

    } else if(relational == LESS) {

        if(holds_alternative<double>(lValue) && holds_alternative<double>(rValue)) {
            return get<double>(lValue) < get<double>(rValue);
        } else if(holds_alternative<int>(lValue) && holds_alternative<int>(rValue)) {
            return get<int>(lValue) < get<int>(rValue);
        }

        throw runtime_error("Operands must be numbers.");  

Here is the error I am getting:

[tester::#IB5] Running tests for Stage #IB5 (Evaluating Expressions - Runtime Errors: Relational Operators)
[tester::#IB5] [test-1] Running test case: 1
[tester::#IB5] [test-1] Writing contents to ./test.lox:
[tester::#IB5] [test-1.lox] "baz" < true
[tester::#IB5] [test-1] $ ./your_program.sh evaluate test.lox
[your_program] Operands must be numbers.
[tester::#IB5] [test-1] expected runtime error (exit code 70), got exit code -1
[tester::#IB5] [test-1] Test failed

And here is my github repo for this project:

If anybody can help me with this, I would greatly appreciate it.

Hey @abdelshafei, I tried running your code against the previous stages, but it’s actually no longer passing a previous stage #EA6 (Scanning: Lexical errors).

Suggestions:

  1. Use our CLI to test against previous stages by running:
codecrafters test --previous
  1. Focus on fixing the early stages first, as later stages depend on them.

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.