Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Improve libaktualizr API exceptions. #1754

Merged
merged 9 commits into from
Sep 2, 2020

Conversation

pattivacek
Copy link
Collaborator

@pattivacek pattivacek commented Sep 1, 2020

Generally, only fatal exceptions should be thrown through the API. Non-fatal exceptions are caught inside libaktualizr and converted to error codes. Also:

  • All Secondary communication is now wrapped in try-catches.
  • JSON parsing is wrapped in try-catches when appropriate. (The Uptane code does most of the json parsing, and that's already covered by higher-level try-catches in SotaUptaneClient.)
  • Uptane exceptions are no longer be exposed through the API.
  • All SQL exceptions are thrown as SQLException or a subclass thereof (SQLInternalException).
  • The list of exceptions thrown in aktualizr.h has been revised accordingly, and a few inaccuracies have been corrected.
  • Some logging and error messages have been improved.
  • Some unused types have been removed.

There is probably still room for improvement in the SQL code. However, it's generally fairly low-level and only internally relevant, so it didn't seem worth the effort to refactor it too substantially. Some functions return bools while others throw exceptions, and some do both. It might be nice to only throw exceptions, but that would take some work to get right, and no one seems to bothered by the current state of affairs.

In each case, the "TODO(OTA-2178)" comments were no longer helpful. The
iterator exceptions are fine as is, and if the SQL code fails, it is
acceptable to throw that through the API, since that is probably a
serious issue.

Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
The user won't understand what to do with that exception, so better to
print an error with some context. This scenario is most likely
recoverable anyway.

Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Since these calls can call custom/external code, this is the safest
course of action. All errors are printed to the log and errors are
returned through the API as appropriate. The assumption is that these
cases are generally recoverable.

Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Memory and mutex-related exceptions can be thrown almost everywhere, and
those represent situations that are most likely difficult to recover
from.

Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
This is definitely recoverable.

Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Most were already caught as part of the metadata parsing in the Uptane
namespace, but some miscellaneous things could still slip through. They
are highly unlikely, but just in case, catch them. They are generally
recoverable and do not need to be passed through the API.

Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Use SQLInternalException for the specifically low-level errors. Improve
some of the context as well.

Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
@pattivacek pattivacek force-pushed the feat/OTA-5089/better-exceptions branch from 26688f1 to 39c90b5 Compare September 1, 2020 09:56
@codecov-commenter
Copy link

Codecov Report

Merging #1754 into master will decrease coverage by 5.63%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1754      +/-   ##
==========================================
- Coverage   81.98%   76.35%   -5.64%     
==========================================
  Files         178      178              
  Lines       12481    13415     +934     
==========================================
+ Hits        10233    10243      +10     
- Misses       2248     3172     +924     
Impacted Files Coverage Δ
include/libaktualizr/aktualizr.h 66.66% <ø> (-33.34%) ⬇️
include/libaktualizr/types.h 70.96% <ø> (-20.77%) ⬇️
src/libaktualizr/storage/sqlstorage_base.cc 74.82% <0.00%> (-2.05%) ⬇️
src/libaktualizr/uptane/iterator.cc 87.61% <0.00%> (ø)
src/libaktualizr/utilities/types.cc 62.50% <ø> (-13.45%) ⬇️
src/libaktualizr/storage/sqlstorage.cc 64.18% <16.81%> (-14.70%) ⬇️
src/libaktualizr/storage/sql_utils.h 66.00% <25.00%> (-17.12%) ⬇️
src/libaktualizr/uptane/manifest.cc 60.31% <25.00%> (-39.69%) ⬇️
src/libaktualizr/primary/initializer.cc 72.08% <28.57%> (-19.41%) ⬇️
src/libaktualizr/uptane/directorrepository.cc 82.95% <40.00%> (-10.64%) ⬇️
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb9c8f7...39c90b5. Read the comment docs.

@pattivacek pattivacek merged commit c0810eb into master Sep 2, 2020
@pattivacek pattivacek deleted the feat/OTA-5089/better-exceptions branch September 2, 2020 06:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants