Skip to content

Use PyBaseExceptionRef in places where we expect exceptions - #1644

Merged
coolreader18 merged 10 commits into
masterfrom
coolreader18/exc-cleanup
Dec 29, 2019
Merged

Use PyBaseExceptionRef in places where we expect exceptions#1644
coolreader18 merged 10 commits into
masterfrom
coolreader18/exc-cleanup

Conversation

@coolreader18

Copy link
Copy Markdown
Member

e.g. in PyResult, the exception stack, and any function that does an operation on an exception. I also noticed a bug where if the from argument to raise was missing, it would still overwrite the __cause__ on the exception as if it had been raised from None.

@coolreader18
coolreader18 force-pushed the coolreader18/exc-cleanup branch from e83be39 to b8a62b9 Compare December 24, 2019 23:29

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly, it looks good to me. But I didn't get much about frame.rs part

Comment thread vm/src/exceptions.rs Outdated

#[pyproperty(name = "__traceback__", setter)]
fn set_traceback(&self, traceback: Option<PyTracebackRef>, vm: &VirtualMachine) -> PyResult {
fn setter_traceback(&self, traceback: Option<PyTracebackRef>, vm: &VirtualMachine) -> PyResult {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks a little bit awkward that getter has get_ prefixed name but setter has setter_ prefixed names

@coolreader18 coolreader18 Dec 26, 2019

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree, but it was conflicting with the public setter methods so I just renamed them to something that seemed appropriate. I might go with __traceback__/set____traceback__, but that might be too many underscores 😃

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adapting #1647 for these methods? This will not fit for everytime but fortunately set_traceback and setter_traceback can share the implementation in this case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good, it would be nice if we could omit the &VirtualMachine parameter too as it's not really necessary, but I'm not sure if that's doable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you check #1649 for this?

Comment thread vm/src/exceptions.rs Outdated
Comment thread vm/src/frame.rs
Comment thread vm/src/frame.rs
Comment thread vm/src/obj/objtype.rs Outdated
Comment thread vm/src/pyobject.rs
Comment thread vm/src/stdlib/os.rs
Comment thread vm/src/vm.rs Outdated
Comment thread vm/src/vm.rs Outdated
})
}
};
let exc_type = if let Ok(exc) = PyBaseExceptionRef::try_from_object(self, exc_type.clone())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not create this exc_type variable, but do the condition checking in the code where the exc_type is used below. In fact it might make sense to create another helper function figure_out_exception which returns a PyResult, so we can do:

let exc = figure_out_exception(exc_type, exc_value)?;  // figure out a better name for this function ;)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that function is basically normalize_exception. I've reworked the code; I think it's a lot cleaner and easier to follow now.

Comment thread vm/src/vm.rs Outdated

@windelbouwman windelbouwman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A big change, but it does look like a move in the proper direction. I'm unable to grasp it all though :)

@coolreader18
coolreader18 force-pushed the coolreader18/exc-cleanup branch from b8a62b9 to ec3e402 Compare December 28, 2019 04:13
@coolreader18

Copy link
Copy Markdown
Member Author

@windelbouwman would mind reviewing the latest 4 commits? I think I addressed your comments on normalize.

@windelbouwman windelbouwman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I did not see all change, but it looks good I guess!

@coolreader18
coolreader18 merged commit deee1f7 into master Dec 29, 2019
@coolreader18
coolreader18 deleted the coolreader18/exc-cleanup branch January 7, 2020 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants