Err instead of panic for host object attribute error #288

Merged
sb10q merged 1 commits from 281-host-obj-attribute-err into master 2022-05-18 06:36:08 +08:00
2 changed files with 8 additions and 2 deletions
Showing only changes of commit 09820e5aed - Show all commits

View File

@ -671,7 +671,10 @@ impl Nac3 {
&mut composer.unifier, &mut composer.unifier,
&self.primitive, &self.primitive,
); );
return Err(CompileError::new_err(msg.unwrap_or(e))); return Err(CompileError::new_err(format!(
"compilation failed\n----------\n{}",
msg.unwrap_or(e)
)));
} }
} }
let top_level = Arc::new(composer.make_top_level_context()); let top_level = Arc::new(composer.make_top_level_context());

View File

@ -670,7 +670,10 @@ impl InnerResolver {
if let TypeEnum::TFunc(..) = &*unifier.get_ty(field.1.0) { if let TypeEnum::TFunc(..) = &*unifier.get_ty(field.1.0) {
continue; continue;
} else { } else {
let field_data = obj.getattr(&name)?; let field_data = match obj.getattr(&name) {
Ok(d) => d,
Err(e) => return Ok(Err(format!("{}", e))),
};
let ty = match self let ty = match self
Outdated
Review

Why?

Why?
Outdated
Review

Won't other types of errors have the same issue? I don't see what's special about AttributeError. The default behavior of printing AttributeError("...") seems acceptable to me (for now) and should be simple enough.

Won't other types of errors have the same issue? I don't see what's special about AttributeError. The default behavior of printing ``AttributeError("...")`` seems acceptable to me (for now) and should be simple enough.

Here I think that it should only catch AttributeError because we are using getattr to get the member of an object, so we are only expecting AttributeError to happen here. Other errors should not happen.

Here I think that it should only catch `AttributeError` because we are using `getattr` to get the member of an object, so we are only expecting `AttributeError` to happen here. Other errors should not happen.

Hmm maybe it's better to use unreachable! to mark that internal error and panic here?

Hmm maybe it's better to use `unreachable!` to mark that internal error and panic here?
.get_obj_type(py, field_data, unifier, defs, primitives)? .get_obj_type(py, field_data, unifier, defs, primitives)?
{ {