question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: Better error handling for 'native' plugins.

See original GitHub issue

Feature Request

Describe the Feature Request

Hey guys, we are running into issues when handling plugins on native devices.

For example the Geolocation.getCurrentLocation() function returns a different error object on web than it does on native devices.

The error object on this particular function on native devices currently only holds a message property. Without any documentation, it is hard to see what kind of errors it may throw and to write code around handling these errors.

The error object on web is the GeolocationPositionError. It’s a lot easier to write different methods around the types of errors it can throw.

The same goes for other plugins like the Camera plugin.

Platform Support Requested

  • Android
  • iOS
  • Electron
  • Web

Describe Preferred Solution

The preferred solution would be a single error object that we can use to handle the error in the same way across platforms. It would also help to have documentation of the errors that certain functions throw. I currently have to search for the error types in the @capacitor/core package.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
diachedeliccommented, Apr 15, 2020

It is difficult to categorise Filesystem errors across different platforms, for example:

try {
  await Filesystem.stat({ directory, path })
} catch (err) {
  const androidFileNotFound = err.message === 'File does not exist'
  const iosFileNotFound = err.message.includes('was not found')

  if (androidFileNotFound || iosFileNotFound) {
    return null
  } else {
    // unknown error
    throw err
  }
}

Perhaps well documented err.code properties could be implemented?

1reaction
TaaBooThreecommented, Nov 13, 2020

It is difficult to categorise Filesystem errors across different platforms, for example:

try {
  await Filesystem.stat({ directory, path })
} catch (err) {
  const androidFileNotFound = err.message === 'File does not exist'
  const iosFileNotFound = err.message.includes('was not found')

  if (androidFileNotFound || iosFileNotFound) {
    return null
  } else {
    // unknown error
    throw err
  }
}

Perhaps well documented err.code properties could be implemented?

I’d like to see a general error for a file not found scenario as well as the actual platform specific error. Some people might want to handle platform specific errors after all.

One thing that would really help is just documentation around the errors object it throws and the possible messages you can get. I have no idea what kind of error scenarios I can expect and how to handle them properly without going through the source code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Handling | Flipper
To gracefully handle errors in Flipper, use the following classes: FlipperResponder - an instance is provided to the client plugin on every method...
Read more >
Better error handling in JavaScript | by Iain Collins - Medium
Better error handling in JavaScript. How and why to use custom error types in JavaScript. Handling errors well can be tricky. How Error()...
Read more >
React Error Handling and Logging Best Practices
This article will go over best practices for error handling and logging in React for different scenarios. Let's get started.
Read more >
Plugins - Cypress Documentation
Adds XPath command. This repo is also a good example of using custom commands to do retries, provide TypeScript definitions, etc. #xpath#commands ...
Read more >
massive x error loading preset
Native Instruments has just released 3 new Massive X presets and ... featuring optimizations and effects specifically made for improving portrait photos.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found