Issue
When I compile a program using GCC and there is a part of the line that is incorrect, the error message I receive usually annotates the incorrect part. For example, an invalid header file leads to
prog.cpp:1:10: fatal error: iostreamm: No such file or directory
#include <iostreamm>
^~~~~~~~~~~
compilation terminated.
Notice the ^
above that tells exactly where in the statement the error is. When I run a Python script that does a nontrivial task, a similar ^
does not appear, but I believe there is enough information for the interpreter to output one. Is there way I could view nicer ^
annotated error messages from the Python interpreter?
Example Python error message:
Traceback (most recent call last):
File "hw1/code/assignment.py", line 255, in <module>
main()
File "hw1/code/assignment.py", line 245, in main
train(my_model, train_inputs, train_labels)
File "hw1/code/assignment.py", line 157, in train
grad_w, grad_b = model.back_propagation(train_inputs[i], probs, train_labels[i])
File "hw1/code/assignment.py", line 96, in back_propagation
grad_w[j, k] += self.learning_rate * (y_j - probs[j, i]) * inputs[i, k]
IndexError: index 10 is out of bounds for axis 1 with size 10
Wanted Python error message:
Traceback (most recent call last):
File "hw1/code/assignment.py", line 255, in <module>
main()
File "hw1/code/assignment.py", line 245, in main
train(my_model, train_inputs, train_labels)
File "hw1/code/assignment.py", line 157, in train
grad_w, grad_b = model.back_propagation(train_inputs[i], probs, train_labels[i])
File "hw1/code/assignment.py", line 96, in back_propagation
grad_w[j, k] += self.learning_rate * (y_j - probs[j, i]) * inputs[i, k]
^~~~~~~~~~~~~~~~~~~~~
IndexError: index 10 is out of bounds for axis 1 with size 10
Solution
You do get such arrows for syntax errors, which is the closest equivalent to a compilation error for the Python implementation.
What you are asking for is arrows pointing to the sub-expressions that lead to raise
(throw
in C++). Neither GCC nor CPython at the moment do that.
Answered By - Caleth