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

Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[camera_windows] Use CameraAccessDenied error code for camera permission errors #6154

Merged
merged 5 commits into from
Aug 1, 2022

Conversation

loic-sharma
Copy link
Member

@loic-sharma loic-sharma commented Jul 29, 2022

Background

The camera plugin reports issues to the Flutter app by throwing CameraExceptions. As per this proposal, we would like to standardize the CameraException's code value so that common errors can be handled consistently across platforms.

This change makes the Windows camera plugin set the error code to CameraAccessDenied when camera permissions were denied. This is a breaking change as previously the error code would've been camera_error or capture_error.

Addresses: flutter/flutter#102098

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.


**BREAKING CHANGES**:
* `CameraException.code` now has value `"CameraAccessDenied"` if camera access permission was denied.
* `CameraException.code` now has value `"camera_error"` if error occurs during capture.
Copy link
Member Author

Choose a reason for hiding this comment

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

This may not be clear, but a camera permission error during capture will still have a code of CameraAccessDenied. Let me know if you have suggestions on how to word this better.

@@ -250,7 +283,8 @@ void CameraImpl::OnCaptureError(const std::string& error) {
channel->InvokeMethod(kErrorEvent, std::move(message_data));
}

SendErrorForPendingResults("capture_error", error);
Copy link
Member Author

@loic-sharma loic-sharma Jul 29, 2022

Choose a reason for hiding this comment

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

This is a breaking change. This case can be triggered if I unplug my camera while the preview us running. It's not clear why this case had its own error code, it seems better for these error codes to be consistent.

Copy link

@yaakovschectman yaakovschectman left a comment

Choose a reason for hiding this comment

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

This is probably just something I need to learn about as I am new here, my only question is why there are two checks listed as failing (publishable and submit-queue), or what their failure indicates?

@loic-sharma
Copy link
Member Author

loic-sharma commented Jul 29, 2022

@yaakovschectman Good question! You can pop open the Details link next to each failure to learn more about what happened:

  • publishable - Looks like my change is using an invalid version number. I'll need to address this before merging this pull request. That's my mistake.
  • submit-queue - We want the main branch to build and pass tests at all times. Whenever this isn't the case, we should stop merging new things to main until the branch is fixed. Common failures on main branch include flaky tests, or, test failures from post-submit tests (these are tests that aren't run on pull requests until after they have been merged). We'll need to either revert one or more bad commits from main, or, disable/re-run flaky tests. If you haven't already, I recommend reading through this: https://github.com/flutter/flutter/wiki/Tree-hygiene


default:
case CameraResult::kError:
return kCameraError;
Copy link
Member

Choose a reason for hiding this comment

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

Replace the default with a fallthrough with both remaining cases listed.

We should probably add a lint that bans default cases like we do elsewhere, so that we're forced to deal with each usage site if new enum values are ever added.

Copy link
Member Author

@loic-sharma loic-sharma Jul 29, 2022

Choose a reason for hiding this comment

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

I added all the possible cases, however, I wasn't able to remove the default case as that resulted in this error:

... error C2220: the following warning is treated as an error ...
... warning C4715: 'camera_windows::GetErrorCode': not all control paths return a value ...
camera_windows/example unit tests failed to build.

I moved the default case to be the fall-through after all other cases. I'll check if there's some C++ compiler settings I can fiddle with.

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

lgtm modulo nits! Error handling is a lot clearer now! Thanks!

Copy link
Contributor

@hellohuanlin hellohuanlin left a comment

Choose a reason for hiding this comment

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

Thanks for making this change. In the future we should think about further clean up all errors across platforms, and for other plugins as well.

@@ -16,6 +16,25 @@ constexpr char kVideoRecordedEvent[] = "video_recorded";
constexpr char kCameraClosingEvent[] = "camera_closing";
constexpr char kErrorEvent[] = "error";

// Camera error codes
constexpr char kCameraAccessDenied[] = "CameraAccessDenied";
constexpr char kCameraError[] = "camera_error";
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe camera_error_others?

Copy link
Member Author

@loic-sharma loic-sharma Jul 29, 2022

Choose a reason for hiding this comment

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

The existing plugin already uses camera_error as its fallback error code. Changing this to camera_error_others would be a breaking change, which I'd rather do in a separate pull request since this one focuses on introducing camera permission errors.

Also, if we were to do this breaking change I'd prefer to go to a standardized fallback error code. None exists today, but perhaps CameraError would be better aligned to the other standardized camera error code (like CameraAccessDenied, CameraAccessRestricted, CameraAccessDeniedWithoutPrompt)?

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

LGTM stamp from a Japanese personal seal

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 1, 2022
@auto-submit auto-submit bot merged commit 0d6d03a into flutter:main Aug 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 2, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 2, 2022
yutaaraki-toydium pushed a commit to yutaaraki-toydium/plugins that referenced this pull request Aug 12, 2022
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: camera platform-windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants