Convert some runtime_error into type_error, fix a bug converting dict to struct