Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Conversation

@tamara-schmitz
Copy link
Contributor

@tamara-schmitz tamara-schmitz commented Feb 21, 2025

Let dbus clients query the error codes that occur during installation.
There are no error codes exposed via Dbus to the user. See #690.

The RInstallError enum declared in include/install.h already defines error codes that are used throughout the installation process. Let's expose its value via dbus as LastErrorCode.

The goal of this feature is to allow applications to understand error states better without having to rely on string parsing.

I ran ./uncrustify.sh and meson test -C build as requested by the contribution guidelines.

I have marked this a draft first as I would like to have feedback on what is missing here, aka examples, documentation?

@codecov
Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.28%. Comparing base (69fbd8f) to head (dd0e307).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1635      +/-   ##
==========================================
+ Coverage   84.27%   84.28%   +0.01%     
==========================================
  Files          71       71              
  Lines       22037    22052      +15     
==========================================
+ Hits        18571    18586      +15     
  Misses       3466     3466              
Flag Coverage Δ
service=false 80.74% <46.15%> (-0.03%) ⬇️
service=true 84.23% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@jluebbe jluebbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the short/synchronous D-Bus calls, I prefer to return the error via D-Bus directly, but's that's not possible for installations, which are only triggered via D-Bus.

If @ejoerns fine with this approach, we'd need a list of the possible error codes in the documentation and perhaps we should use explicit numbering for the enum.

GQuark r_install_error_quark(void);

typedef enum {
R_INSTALL_ERROR_NOERROR,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the existing error codes, but the shouldn't be exposed yet. @ejoerns?

Perhaps we can use -1 for R_INSTALL_ERROR_NOERROR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler does not guarantee a specific enum number unless specified right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not researched it again, but I think in practice it starts at 0 and counts up.

Copy link
Contributor Author

@tamara-schmitz tamara-schmitz Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed to my fork and now made NOERROR explicitly -1.

src/service.c Outdated
r_installer_set_last_error(r_installer, message);
}

void set_last_error_code(const int32_t code)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps let set_last_error() handle this as well by adding an argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do. Could also just have it accept a GError as an argument.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yes. In that case, we also need to have a way to clear it, perhaps by passing NULL as the GError* argument.

@jluebbe jluebbe requested a review from ejoerns February 24, 2025 11:32
@jluebbe jluebbe added the enhancement Adds new functionality or enhanced handling to RAUC label Feb 24, 2025
@tamara-schmitz tamara-schmitz force-pushed the master branch 2 times, most recently from 73d5735 to f8878f3 Compare February 25, 2025 18:05
Let's dbus clients query the error codes that occur
during installation.
The RInstallError enum already defines error codes
that are used throughout the installation process.
@ejoerns
Copy link
Member

ejoerns commented Feb 27, 2025

Well, it isn't that easy and I would still consider my comment in #690 valid:

In general, I really appreciate the idea to use error-specific exit codes. But, this would pretty sure be independent of the codes we currently use for error reporting as these have the concept of a (domain, code) tuple that we would have to map to a single code being returned.

The Glib errors you can get and would set in set_last_error(), are all the errors that do_install_bundle() may return.
Already on this level, we have almost 10 different function calls from which we just propagate the GError they returned.
Take check_bundle() for example which either returns GErrors of the domain R_BUNDLE_ERROR or again propagates errors from other function calls.

With the current code and handling there is no way to guarantee that do_install_bundle() returns errors of domain R_INSTALL_ERROR only. This is why I noted that the returned errors may be independent of the GError domain, code tuple. An alternative could be to ensure that on this level, all errors are properly mapped to GErrors of the R_INSTALL_ERROR domain.

As much as I would like to see the situation with end-user error reporting improved, I don't think it's an easy task to do. Because as soon as we expose them, they become an API and thus must remain stable. A feasible way I could think of is to map all errors to a generic "Installation Failed" code first and step by step identify and catch GErrors the user might benefit from when being able to distinguish them from the generic error. Then map these errors to distinct error codes.

Thinking of this, I notice the 'high-level error' is something that we already have. It's the Completed signal. The API says it returns 0 for success. However, it does not specify what the error codes are. Currently used error codes (from the code) are

  • 1 -> Installation failed / Already processing a different method / Failed to launch install thread.
  • 2 -> Unsupported variant dict key.

These could easily be extended I guess. Even since it gets the most errors directly from the do_install_bundle() return (which still is a gboolean).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Adds new functionality or enhanced handling to RAUC needs rework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants