From: Mike G. v. a. <we...@ma...> - 2009-01-25 22:20:46
|
Log Message: ----------- moving exception catching to DB instead of DB::Schema Modified Files: -------------- webwork2/lib/WeBWorK: DB.pm Revision Data ------------- Index: DB.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/DB.pm,v retrieving revision 1.109 retrieving revision 1.110 diff -Llib/WeBWorK/DB.pm -Llib/WeBWorK/DB.pm -u -r1.109 -r1.110 --- lib/WeBWorK/DB.pm +++ lib/WeBWorK/DB.pm @@ -151,6 +151,10 @@ 'WeBWorK::DB::Ex::DependencyNotFound' => { isa => 'WeBWorK::DB::Ex::RecordNotFound', }, + 'WeBWorK::DB::Ex::TableMissing' => { + isa => 'WeBWorK::DB::Ex', + description =>"missing table", + }, ); ################################################################################ @@ -496,11 +500,20 @@ eval { return $self->{user}->add($User); }; - if (my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists) { + if (my $ex = caught WeBWorK::DB::Ex::RecordExists) { croak "addUser: user exists (perhaps you meant to use putUser?)"; } elsif ($@) { die $@; } + # FIXME about these exceptions: eventually the exceptions should be part of + # WeBWorK::DB rather than WeBWorK::DB::Schema, and we should just let them + # through to the calling code. however, right now we have code that checks + # for the string "... exists" in the error message, so we need to convert + # here. + # + # WeBWorK::DB::Ex::RecordExists + # WeBWorK::DB::Ex::DependencyNotFound - i.e. inserting a password for a nonexistent user + # ? } sub putUser { @@ -592,7 +605,7 @@ eval { return $self->{password}->add($Password); }; - if (my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists) { + if (my $ex = caught WeBWorK::DB::Ex::RecordExists) { croak "addPassword: password exists (perhaps you meant to use putPassword?)"; } elsif ($@) { die $@; @@ -685,7 +698,7 @@ eval { return $self->{permission}->add($PermissionLevel); }; - if (my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists) { + if (my $ex = caught WeBWorK::DB::Ex::RecordExists) { croak "addPermissionLevel: permission level exists (perhaps you meant to use putPermissionLevel?)"; } elsif ($@) { die $@; @@ -771,7 +784,7 @@ eval { return $self->{key}->add($Key); }; - if (my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists) { + if (my $ex = caught WeBWorK::DB::Ex::RecordExists) { croak "addKey: key exists (perhaps you meant to use putKey?)"; } elsif ($@) { die $@; @@ -904,7 +917,7 @@ eval { return $self->{locations}->add($Location); }; - if ( my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists ) { + if ( my $ex = caught WeBWorK::DB::Ex::RecordExists ) { croak "addLocation: location exists (perhaps you meant to use putLocation?)"; } elsif ($@) { die $@; @@ -1005,7 +1018,7 @@ eval { return $self->{location_addresses}->add($LocationAddress); }; - if (my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists) { + if (my $ex = caught WeBWorK::DB::Ex::RecordExists) { croak "addLocationAddress: location address exists (perhaps you meant to use putLocationAddress?)"; } elsif ($@) { die $@; @@ -1076,7 +1089,7 @@ return $self->{set}->add($GlobalSet); }; - if (my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists) { + if (my $ex = caught WeBWorK::DB::Ex::RecordExists) { croak "addGlobalSet: global set exists (perhaps you meant to use putGlobalSet?)"; } elsif ($@) { die $@; @@ -1168,7 +1181,7 @@ eval { return $self->{set_user}->add($UserSet); }; - if (my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists) { + if (my $ex = caught WeBWorK::DB::Ex::RecordExists) { croak "addUserSet: user set exists (perhaps you meant to use putUserSet?)"; } elsif ($@) { die $@; @@ -1280,7 +1293,7 @@ eval { return $self->{set_version}->add($SetVersion); }; - if (my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists) { + if (my $ex = caught WeBWorK::DB::Ex::RecordExists) { croak "addSetVersion: set version exists (perhaps you meant to use putSetVersion?)"; } elsif ($@) { die $@; @@ -1394,7 +1407,7 @@ eval { return $self->{set_locations}->add($GlobalSetLocation); }; - if (my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists) { + if (my $ex = caught WeBWorK::DB::Ex::RecordExists) { croak "addGlobalSetLocation: global set_location exists (perhaps you meant to use putGlobalSetLocation?)"; } elsif ($@) { die $@; @@ -1493,7 +1506,7 @@ eval { return $self->{set_locations_user}->add($UserSetLocation); }; - if (my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists) { + if (my $ex = caught WeBWorK::DB::Ex::RecordExists) { croak "addUserSetLocation: user set_location exists (perhaps you meant to use putUserSetLocation?)"; } elsif ($@) { die $@; @@ -1595,7 +1608,7 @@ eval { return $self->{problem}->add($GlobalProblem); }; - if (my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists) { + if (my $ex = caught WeBWorK::DB::Ex::RecordExists) { croak "addGlobalProblem: global problem exists (perhaps you meant to use putGlobalProblem?)"; } elsif ($@) { die $@; @@ -1693,7 +1706,7 @@ eval { return $self->{problem_user}->add($UserProblem); }; - if (my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists) { + if (my $ex = caught WeBWorK::DB::Ex::RecordExists) { croak "addUserProblem: user problem exists (perhaps you meant to use putUserProblem?)"; } elsif ($@) { die $@; @@ -1837,7 +1850,7 @@ eval { return $self->{problem_version}->add($ProblemVersion); }; - if (my $ex = caught WeBWorK::DB::Schema::Ex::RecordExists) { + if (my $ex = caught WeBWorK::DB::Ex::RecordExists) { croak "addProblemVersion: problem version exists (perhaps you meant to use putProblemVersion?)"; } elsif ($@) { die $@; |