-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[camera_windows] Use CameraAccessDenied
error code for camera permission errors
#6154
Conversation
|
||
**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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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?
@yaakovschectman Good question! You can pop open the
|
|
||
default: | ||
case CameraResult::kError: | ||
return kCameraError; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
There was a problem hiding this 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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe camera_error_others
?
There was a problem hiding this comment.
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
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…mera permission errors (flutter/plugins#6154)
…mera permission errors (flutter/plugins#6154)
Background
The camera plugin reports issues to the Flutter app by throwing
CameraException
s. As per this proposal, we would like to standardize theCameraException
'scode
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 beencamera_error
orcapture_error
.Addresses: flutter/flutter#102098
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.