Commit 9098ccf1 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Improve tracebacks from eval/exec

Previously we would say that they were coming from the same
file as they are executed in, typically on line 1, which would
give a misleading traceback saying that the module docstring
threw the error.

Now, do what CPython does and say that the file is "<string>",
and don't display the source line.

The method is pretty hacky right now, where it only makes this
adjustment when generating the traceback.  Instead we should probably
get rid of storing the BoxedModule in the sourceinfo in the first place,
and just passing around the relevant info (fn, locals, globals, etc).
parent bbadf8a6
......@@ -476,7 +476,17 @@ static const LineInfo* lineInfoForFrame(PythonFrameIterator& frame_it) {
assert(cf);
auto source = cf->clfunc->source;
return new LineInfo(current_stmt->lineno, current_stmt->col_offset, source->parent_module->fn, source->getName());
// Hack: the "filename" for eval and exec statements is "<string>", not the filename
// of the parent module. We can't currently represent this the same way that CPython does
// (but we probably should), so just check that here:
const std::string* fn = &source->parent_module->fn;
if (source->ast->type == AST_TYPE::Suite /* exec */ || source->ast->type == AST_TYPE::Expression /* eval */) {
static const std::string string_str("<string>");
fn = &string_str;
}
return new LineInfo(current_stmt->lineno, current_stmt->col_offset, *fn, source->getName());
}
static StatCounter us_gettraceback("us_gettraceback");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment