1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-05 15:05:48 +02:00

Return UnknownError from errorTypeFromCode() for invalid error codes.

The prior behavior was to throw an exception but this was not very helpful when something unexpected happened.  Better to at least emit the error message even if the error code is not very helpful.
This commit is contained in:
David Steele 2019-01-14 21:34:22 +02:00
parent 2b02d37602
commit aab9e38b9a
3 changed files with 7 additions and 3 deletions

View File

@ -41,6 +41,10 @@
<p>Allow empty arrays in JSON parser.</p>
</release-item>
<release-item>
<p>Return <code>UnknownError</code> from <code>errorTypeFromCode()</code> for invalid error codes.</p>
</release-item>
<release-item>
<p>Null-terminate list returned by <code>strLstPtr()</code>.</p>
</release-item>

View File

@ -109,7 +109,7 @@ errorTypeFromCode(int code)
// Error if type was not found
if (result == NULL)
THROW_FMT(AssertError, "could not find error type for code '%d'", code);
result = &UnknownError;
return result;
}

View File

@ -247,8 +247,8 @@ testRun(void)
}
CATCH_ANY()
{
assert(errorCode() == AssertError.code);
assert(strcmp(errorMessage(), "could not find error type for code '777'") == 0);
assert(errorCode() == UnknownError.code);
assert(strcmp(errorMessage(), "message") == 0);
}
TRY_END();
}