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

Update feature detection example #341

Merged
merged 1 commit into from Feb 13, 2018

Conversation

alexshalamov
Copy link

@alexshalamov alexshalamov commented Feb 9, 2018

Fixes: #339


Preview | Diff

@anssiko
Copy link
Member

anssiko commented Feb 9, 2018

@kenchris to also review the feature detection example code.

} else if (error.name === 'ReferenceError') {
console.log('Sensor is not supported by the User Agent.');
} else {
throw error;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is throwing considered here?

Copy link
Author

Choose a reason for hiding this comment

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

If there are other errors that handled in the if / else blocks, I think it is better to re-throw them, rather than supressing or logging.

Copy link
Contributor

Choose a reason for hiding this comment

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

throwing doesn't make it robust though, an error happened and what ever happened you handled it... throwing can end up affecting other systems, like if someone else ends up catching it

Copy link
Author

Choose a reason for hiding this comment

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

This is outside of scope of this example. Robust application should not suppress error propagation to avoid unpredictable behavior. I can fix throwing from error handler.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

index.bs Outdated
accelerometer.addEventListener('error', event => handleErrors(event.error));
accelerometer.addEventListener('reading', () => reloadOnShake(accelerometer));
accelerometer.start();
} catch (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 comment like // Handle construction errors

Copy link
Author

Choose a reason for hiding this comment

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

done

index.bs Outdated
let accelerometer = null;
try {
accelerometer = new Accelerometer({ frequency: 10 });
accelerometer.addEventListener('error', event => handleErrors(event.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 comment // handle runtime errors

Copy link
Contributor

Choose a reason for hiding this comment

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

what happens when handleErrors throws from a runtime error?

Copy link
Author

Choose a reason for hiding this comment

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

log to console :) unhandled exception

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to add that as a comment above the throw

Copy link
Contributor

Choose a reason for hiding this comment

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

Then the throw makes even less sense... why not print to console straight away in both cases, you could use console.error()

Copy link
Author

Choose a reason for hiding this comment

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

Added comment for runtime errors.

index.bs Outdated
handleErrors(error);
}

function handleErrors(error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Its called handleErrors but not doing much handling :-) more like logging

Copy link
Author

Choose a reason for hiding this comment

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

Well, it is an example and not a full blown app :) Do you have some suggestions? It is app specific, to define behavior for particular error condition. E.g, fallback to DevMotion, show notification, etc.

index.bs Outdated
}

function handleErrors(error) {
if (error.name === 'NotAllowedError') {
Copy link
Contributor

Choose a reason for hiding this comment

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

// Do proper error handling here, like show notification, or fallback to other sensor;
// whatever makes the most sense for your application scenario.

Copy link
Author

Choose a reason for hiding this comment

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

Added text to example description.

Copy link

@pozdnyakov pozdnyakov left a comment

Choose a reason for hiding this comment

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

lgtm

@alexshalamov alexshalamov merged commit fa95e5c into w3c:master Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants