Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling in backup restore #4791

Merged
merged 1 commit into from
Dec 29, 2023
Merged

Conversation

mdegat01
Copy link
Contributor

Proposed change

When something goes wrong in restore users often have no idea since all we do is log a warning or error. When we do return an error all the UI says is "something went wrong, check the logs". This is particularly egregious during onboarding since the users can't even check supervisor logs.

This PR changes it so we raise an exception with what went wrong if the restore process did not begin due to invalid input or if restore was halted with an exception. If restore proceeded to the end but something went wrong along the way we always return False to tell users to check the logs to see what worked and what didn't.

The last part is not ideal but currently we have no other option. Restore can be partially successful, we don't have a good way to inform and display the details of what happened in the UI in this case. And if restore stopped Home Assistant then the UI can't actually display the response at all since it lost its connection to Supervisor. There are additional improvements to be made here that we'll follow up on in another PR.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to the supervisor)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to cli pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast supervisor tests)
  • Tests have been added to verify that the new code works.

If API endpoints of add-on configuration are added/changed:

@mdegat01 mdegat01 added the refactor A code change that neither fixes a bug nor adds a feature label Dec 28, 2023
@mdegat01 mdegat01 requested a review from agners December 28, 2023 21:56
Comment on lines +484 to +485
if attr in data:
self._data[attr] = data[attr]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm aware this change feels unrelated to the PR. However after the changes this failed tests. Many of these attributes are vol.Maybe in the schema so they may not exist (and refresh_token in particular did not exist in our mock backups). This is an example of an error we were hiding. Nothing was raised and all we did was log an error so the test appeared to succeed, now it needs to be fixed.

@pvizeli pvizeli merged commit 6c66a7b into main Dec 29, 2023
23 checks passed
@pvizeli pvizeli deleted the better-error-handling-backup branch December 29, 2023 10:45
raise BackupInvalidError(
f"Backup was made on supervisor version {backup.supervisor_version}, "
f"can't restore on {self.sys_supervisor.version}. Must update supervisor first.",
_LOGGER.error,
Copy link
Member

Choose a reason for hiding this comment

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

What is the concern exactly to disallow restoring backup? Can we maybe have a backup version number instead, and rely on that?

E.g. it would be nice if people can restore a backup taken on the beta channel on the stable channel (which potentially has an older Supervisor). This check currently prevents this. From what I understand this was possible before #3769.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no way to rollback a supervisor update. If a user goes from beta channel to stable channel, supervisor remains on the beta channel version until there is a version on the stable channel which is newer then itself. So I'm not entirely sure how this situation is occurring, other then users directly manipulating things with the docker CLI.

The reason though is that we don't attempt to maintain backwards compatibility with internal things. For example:

  1. We may rewrite the schema of saved config files in a newer supervisor version. The upgrade must maintain backwards compatibility here, that doesn't mean its reversible though.
  2. We may enhance/change the schema addons use for their config. A user may have installed or updated to a version of an addon that makes use of these new features. Older versions of supervisor will then fail processing these addons.
  3. We may have changed the schema/structure of backups. It may not even be possible to successfully restore that backup on prior versions of supervisor.

Supervisor isn't designed to go backwards, only forwards. If you do roll back supervisor somehow and try and keep a config/setup you used successfully on that newer version of supervisor we really don't know what will and won't work, its untested space. That's why there is no API for rolling back supervisor.

Copy link
Member

Choose a reason for hiding this comment

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

There is no way to rollback a supervisor update. If a user goes from beta channel to stable channel, supervisor remains on the beta channel version until there is a version on the stable channel which is newer then itself. So I'm not entirely sure how this situation is occurring, other then users directly manipulating things with the docker CLI.

The issue is occurring when taking a backup from an installation on the beta channel and then on the same system start over with a new installation (which starts in stable mode...).

We may rewrite the schema of saved config files in a newer supervisor version. The upgrade must maintain backwards compatibility here, that doesn't mean its reversible though.

At the very least we need to maintain the backward compatibility to read the Supervisor version number, otherwise this functionality would not work either. At that point, we could also maintain a schema version, no?

I understand that we don't want to maintain backwards compatibility in Supervisor, that is also not what I am asking for here.

I am only asking for a schema version to widen the compatibility of a certain backup. It is mainly meant as a convince feature for developers and testers. I myself get constantly into the annoying situation that I can't restore a test backup from one of my tests systems (which are typically on beta/dev channel) on a new installation (which is on stable channel) for no real reason 😢 . Sure, I can hack around, by just opening the backup and manually alter the version number of Supervisor. But why not just introduce a backup schema version? 🤔

@github-actions github-actions bot locked and limited conversation to collaborators Dec 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed refactor A code change that neither fixes a bug nor adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants