You've already forked pgbackrest
							
							
				mirror of
				https://github.com/pgbackrest/pgbackrest.git
				synced 2025-10-30 23:37:45 +02:00 
			
		
		
		
	Added Exception::exceptionCode() and Exception::exceptionMessage() to simplify error handling logic.
This commit is contained in:
		| @@ -147,7 +147,7 @@ sub process | ||||
|         { | ||||
|             my $oException = $@; | ||||
|  | ||||
|             if (isException($oException) && $oException->code() == ERROR_FILE_INVALID) | ||||
|             if (exceptionCode($oException) == ERROR_FILE_INVALID) | ||||
|             { | ||||
|                 my $oRenderOut = $self->{oManifest}->renderOutGet(RENDER_TYPE_HTML, $strPageId); | ||||
|                 $self->{oManifest}->cacheReset($$oRenderOut{source}); | ||||
|   | ||||
| @@ -121,7 +121,7 @@ sub process | ||||
|         { | ||||
|             my $oException = $EVAL_ERROR; | ||||
|  | ||||
|             if (isException($oException) && $oException->code() == ERROR_FILE_INVALID) | ||||
|             if (exceptionCode($oException) == ERROR_FILE_INVALID) | ||||
|             { | ||||
|                 my $oRenderOut = $self->{oManifest}->renderOutGet(RENDER_TYPE_HTML, $strPageId); | ||||
|                 $self->{oManifest}->cacheReset($$oRenderOut{source}); | ||||
|   | ||||
| @@ -248,6 +248,10 @@ | ||||
|                     <release-item> | ||||
|                         <p>Clean up <code>optionValid()</code>/<code>optionTest()</code> logic in <code>Lock.pm</code>.</p> | ||||
|                     </release-item> | ||||
|  | ||||
|                     <release-item> | ||||
|                         <p>Added <code>Exception::exceptionCode()</code> and <code>Exception::exceptionMessage()</code> to simplify error handling logic.</p> | ||||
|                     </release-item> | ||||
|                 </release-refactor-list> | ||||
|             </release-core-list> | ||||
|  | ||||
|   | ||||
| @@ -97,12 +97,9 @@ sub process | ||||
|     # If there is an unhandled error then confess | ||||
|     or do | ||||
|     { | ||||
|         # Confess unhandled errors | ||||
|         confess $EVAL_ERROR if (!isException($EVAL_ERROR)); | ||||
|  | ||||
|         # If this is a backrest error then capture the last code and message | ||||
|         $iResult = $EVAL_ERROR->code(); | ||||
|         $strResultMessage = $EVAL_ERROR->message(); | ||||
|         # Capture error information | ||||
|         $iResult = exceptionCode($EVAL_ERROR); | ||||
|         $strResultMessage = exceptionMessage($EVAL_ERROR->message()); | ||||
|     }; | ||||
|  | ||||
|     # Check archive.info | ||||
| @@ -116,12 +113,9 @@ sub process | ||||
|         } | ||||
|         or do | ||||
|         { | ||||
|             # Confess unhandled errors | ||||
|             confess $EVAL_ERROR if (!isException($EVAL_ERROR)); | ||||
|  | ||||
|             # If this is a backrest error then capture the last code and message | ||||
|             $iResult = $EVAL_ERROR->code(); | ||||
|             $strResultMessage = $EVAL_ERROR->message(); | ||||
|             # Capture error information | ||||
|             $iResult = exceptionCode($EVAL_ERROR); | ||||
|             $strResultMessage = exceptionMessage($EVAL_ERROR->message()); | ||||
|         }; | ||||
|     } | ||||
|  | ||||
| @@ -138,12 +132,9 @@ sub process | ||||
|         # If this is a backrest error then capture the code and message else confess | ||||
|         or do | ||||
|         { | ||||
|             # Confess unhandled errors | ||||
|             confess $EVAL_ERROR if (!isException($EVAL_ERROR)); | ||||
|  | ||||
|             # If this is a backrest error then capture the last code and message | ||||
|             $iResult = $EVAL_ERROR->code(); | ||||
|             $strResultMessage = $EVAL_ERROR->message(); | ||||
|             # Capture error information | ||||
|             $iResult = exceptionCode($EVAL_ERROR); | ||||
|             $strResultMessage = exceptionMessage($EVAL_ERROR->message()); | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -255,4 +255,32 @@ sub isException | ||||
|  | ||||
| push @EXPORT, qw(isException); | ||||
|  | ||||
| #################################################################################################################################### | ||||
| # exceptionCode | ||||
| # | ||||
| # Extract the error code from an exception - if a Perl exception return ERROR_UNKNOWN. | ||||
| #################################################################################################################################### | ||||
| sub exceptionCode | ||||
| { | ||||
|     my $oException = shift; | ||||
|  | ||||
|     return isException($oException) ? $oException->code() : ERROR_UNKNOWN; | ||||
| } | ||||
|  | ||||
| push @EXPORT, qw(exceptionCode); | ||||
|  | ||||
| #################################################################################################################################### | ||||
| # exceptionMessage | ||||
| # | ||||
| # Extract the error message from an exception - if a Perl exception return bare exception. | ||||
| #################################################################################################################################### | ||||
| sub exceptionMessage | ||||
| { | ||||
|     my $oException = shift; | ||||
|  | ||||
|     return isException($oException) ? $oException->message() : $oException; | ||||
| } | ||||
|  | ||||
| push @EXPORT, qw(exceptionMessage); | ||||
|  | ||||
| 1; | ||||
|   | ||||
| @@ -1340,8 +1340,7 @@ sub copy | ||||
|                 my $oException = $EVAL_ERROR; | ||||
|  | ||||
|                 # Ignore error if source file was missing and missing file exception was returned and bIgnoreMissingSource is set | ||||
|                 if ($bIgnoreMissingSource && $strRemote eq 'in' && isException($oException) && | ||||
|                     $oException->code() == ERROR_FILE_MISSING) | ||||
|                 if ($bIgnoreMissingSource && $strRemote eq 'in' && exceptionCode($oException) == ERROR_FILE_MISSING) | ||||
|                 { | ||||
|                     close($hDestinationFile) | ||||
|                         or confess &log(ERROR, "cannot close file ${strDestinationTmpOp}"); | ||||
|   | ||||
| @@ -341,12 +341,9 @@ sub infoFileCreate | ||||
|     } | ||||
|     or do | ||||
|     { | ||||
|         # Confess unhandled errors | ||||
|         confess $EVAL_ERROR if (!isException($EVAL_ERROR)); | ||||
|  | ||||
|         # If this is a backrest error then capture the last code and message | ||||
|         $iResult = $EVAL_ERROR->code(); | ||||
|         $strResultMessage = $EVAL_ERROR->message(); | ||||
|         # Capture error information | ||||
|         $iResult = exceptionCode($EVAL_ERROR); | ||||
|         $strResultMessage = exceptionMessage($EVAL_ERROR->message()); | ||||
|     }; | ||||
|  | ||||
|     # Reset the console logging | ||||
|   | ||||
		Reference in New Issue
	
	Block a user