Tudmotu / gnome-shell-extension-clipboard-indicator

The most popular clipboard manager for GNOME, with over 1M downloads
https://extensions.gnome.org/extension/779/clipboard-indicator/
MIT License
818 stars 166 forks source link

[BUG]: Unhandled promise rejection #458

Closed Edu4rdSHL closed 2 months ago

Edu4rdSHL commented 2 months ago

Hi,

After #454 I'm facing this problem after a while using the keyboard:

Apr 08 20:45:43 SecHackLabs gnome-shell[442208]: Unhandled promise rejection. To suppress this warning, add an error handler to your promise chain with .catch() or a try-catch block around your await expression. Stack trace of the failed promise:
                                                 _promisify/proto[asyncFunc]@resource:///org/gnome/gjs/modules/core/overrides/Gio.js:448:16
                                                 fromJSON/contentType<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:231:77
                                                 fromJSON@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:231:39
                                                 read/</</</entriesPromises<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:95:59
                                                 read/</</<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:93:62
                                                 @resource:///org/gnome/shell/ui/init.js:21:20
Apr 08 20:45:43 SecHackLabs gnome-shell[442208]: Unhandled promise rejection. To suppress this warning, add an error handler to your promise chain with .catch() or a try-catch block around your await expression. Stack trace of the failed promise:
                                                 _promisify/proto[asyncFunc]@resource:///org/gnome/gjs/modules/core/overrides/Gio.js:448:16
                                                 fromJSON/contentType<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:231:77
                                                 fromJSON@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:231:39
                                                 read/</</</entriesPromises<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:95:59
                                                 read/</</<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:93:62
                                                 @resource:///org/gnome/shell/ui/init.js:21:20
Apr 08 20:45:43 SecHackLabs gnome-shell[442208]: Unhandled promise rejection. To suppress this warning, add an error handler to your promise chain with .catch() or a try-catch block around your await expression. Stack trace of the failed promise:
                                                 _promisify/proto[asyncFunc]@resource:///org/gnome/gjs/modules/core/overrides/Gio.js:448:16
                                                 fromJSON/contentType<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:231:77
                                                 fromJSON@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:231:39
                                                 read/</</</entriesPromises<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:95:59
                                                 read/</</<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:93:62
                                                 @resource:///org/gnome/shell/ui/init.js:21:20
Apr 08 20:45:43 SecHackLabs gnome-shell[442208]: Unhandled promise rejection. To suppress this warning, add an error handler to your promise chain with .catch() or a try-catch block around your await expression. Stack trace of the failed promise:
                                                 _promisify/proto[asyncFunc]@resource:///org/gnome/gjs/modules/core/overrides/Gio.js:448:16
                                                 fromJSON/contentType<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:231:77
                                                 fromJSON@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:231:39
                                                 read/</</</entriesPromises<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:95:59
                                                 read/</</<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:93:62
                                                 @resource:///org/gnome/shell/ui/init.js:21:20
Apr 08 20:45:43 SecHackLabs gnome-shell[442208]: Unhandled promise rejection. To suppress this warning, add an error handler to your promise chain with .catch() or a try-catch block around your await expression. Stack trace of the failed promise:
                                                 _promisify/proto[asyncFunc]@resource:///org/gnome/gjs/modules/core/overrides/Gio.js:448:16
                                                 fromJSON/contentType<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:231:77
                                                 fromJSON@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:231:39
                                                 read/</</</entriesPromises<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:95:59
                                                 read/</</<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:93:62
                                                 @resource:///org/gnome/shell/ui/init.js:21:20
Apr 08 20:45:43 SecHackLabs gnome-shell[442208]: Unhandled promise rejection. To suppress this warning, add an error handler to your promise chain with .catch() or a try-catch block around your await expression. Stack trace of the failed promise:
                                                 _promisify/proto[asyncFunc]@resource:///org/gnome/gjs/modules/core/overrides/Gio.js:448:16
                                                 fromJSON/contentType<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:231:77
                                                 fromJSON@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:231:39
                                                 read/</</</entriesPromises<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:95:59
                                                 read/</</<@file:///home/edu4rdshl/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/registry.js:93:62
                                                 @resource:///org/gnome/shell/ui/init.js:21:20

and it stops working as shown in the image: image

EmptyVisual commented 2 months ago

I'm having the same issue, I had to git checkout 3947ceb61737df03e340196f19d900e4bb268764 for it to work again. So whatever commits happened after 3947ceb have broken this extension.

ken-kuro commented 2 months ago

Same issue here, pretty sure that https://github.com/Tudmotu/gnome-shell-extension-clipboard-indicator/commit/8203d3ffd0a7bee888dd50e63a5fa661040d091b broke the extension.

ken-kuro commented 2 months ago

After digging more into the code, I believe that query_info_async() is used in a wrong way @andyholmes. Firstly, you forgot to catch the exception that was rejected from the promised:

const contentType = await new Promise((resolve, reject) => file.query_info_async(null, (obj, res) => {
  try {
    const fileInfo = obj.query_info_finish(res);
    resolve(fileInfo.get_content_type());
  } catch (e) {
    reject(e);
  }
// This catch
}).catch(e => {
  console.error(e);
})
);

Once you do that, you will see the error from query_info_async(): image

I think it would look something like this instead:

const contentType = await file.query_info_async('*', FileQueryInfoFlags.NONE, GLib.PRIORITY_DEFAULT, null, (obj, res) => {
  try {
    const fileInfo = obj.query_info_finish(res);
    return fileInfo.get_content_type();
  } catch (e) {
    console.error(e);
  }
})
);

Please refer to the docs for more info (The read() function in the same file make an usage of the function as well so you can also refer to that.

And one more thing, please check the contentType before performing any operation on it cause it could be null, you should do something like this imo:

if (contentType && !contentType.startsWith('image/') && !contentType.startsWith('text/'))
ken-kuro commented 2 months ago

Since the author stated

DO NOT open unsolicited PRs unless they are for updating translations

so I just made a fork here: https://github.com/ken-kuro/gnome-shell-extension-clipboard-indicator

andyholmes commented 2 months ago

Good catch, thanks for the investigation!

Tudmotu commented 2 months ago

@ken-kuro Thank you for investigating and fixing the issue. Can you kindly open a PR and I will upload it to e.g.o?

Thanks 🙏

ken-kuro commented 2 months ago

I'm happy to, already made one 😄