After adding an opener I can't open any file


#1

I am developing a package and I am using openers.

In the class where I declare de open I have this line to declare it:

atom.workspace.open('package-name://given-string', options object)

In the main file, on the activate method I declare de addOpener:

return atom.workspace.addOpener(function(uri, options) {
  const ref = new URL(uri)
  const protocol = ref.protocol
})

At the beginning of the main file I have the import for URL: import { URL } from 'url', when I reload Atom to have the changes available, if I try to open any file I get an error like this:

Uncaught (in promise) TypeError: Invalid URL
    at URL.onParseComplete (internal/url.js:91:11)
    at parse (internal/url.js:115:11)
    at new URL (internal/url.js:221:5)
    at path-to-file:XX:YY

I don’t know which is the correct way to work with openers and if I should do in another way. I tried with a try/catch and the files are opened but if I try to log the error I don’t see any, and I’m not convinced to use it if the catch statement is not giving nothing.


#2

OK.

I think I have a better solution than using a try/catch to be able to use url. I think that is better to use path.basename(uri) to know if the uri has the correct name.


#3

Please explain a bit more about what you’re trying to do with url. I don’t know if the module can accept non-HTTP-based addresses. I don’t see anything about it in the docs, and most local operations are handled by fs.