You shouldn’t use try / catch for promises, instead use .catch handler (you can also use .then with the second function parameter).
For example:
const response = await browser.runtime.sendMessage({action: "a"}).catch(err => {
console.error(err);
return 'backup response';
}
// warning,`response` will be 'backup response' in case of errors
The nice thing about async functions, is that all errors will automatically bubble up the promise chain. So make sure to use .catch on the right place, maybe on the requestSearchResults().catch(console.error).
See the docs:
Also if you need to reject a promise in your async function, just return Promise.reject() (as an equivalent of throwing an exception, which would work as well).
Regarding the StackOverflow, I would say that’s a bad example, especially because he had to use the second await when extracting text value (else the try catch wouldn’t work). Very misleading… I would recommend checking the MDN docs for fetch examples.
The reason for not using try catch is that you can easily miss exception because it will happen in a different “thread” asynchronously, even if it’s inside the try catch block. And the StackOverflow code is a nice example, by removing the second await the try catch would stop working for errors from response.text() promise.
Regarding your new code, are you sure the error is generated by the line:
In async function you DON’T have to use await for the returned value even if it’s a Promise because you can just return Promise and it will still be part of the main async function!