From f2cc9e1a360e69dc55b8f9f26f367eb4c17ecb5b Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Tue, 26 Mar 2024 13:59:43 +0100 Subject: [PATCH] shell: lib: handle cockpit.user() failures In our test TestLogin.testFailingWebsocket the dbus calls fail which fails the promise which was unhandled leading to the tests to fail due to an unhandled exception. --- pkg/lib/hooks.js | 2 +- pkg/shell/hosts.jsx | 2 +- pkg/shell/indexes.jsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/lib/hooks.js b/pkg/lib/hooks.js index 10c929746a7..270fa80cf51 100644 --- a/pkg/lib/hooks.js +++ b/pkg/lib/hooks.js @@ -88,7 +88,7 @@ export function usePageLocation() { const cockpit_user_promise = cockpit.user(); let cockpit_user = null; -cockpit_user_promise.then(user => { cockpit_user = user }); +cockpit_user_promise.then(user => { cockpit_user = user }).catch(err => console.log(err)); export function useLoggedInUser() { const [user, setUser] = useState(cockpit_user); diff --git a/pkg/shell/hosts.jsx b/pkg/shell/hosts.jsx index 23425a6f447..8e9e7eb547c 100644 --- a/pkg/shell/hosts.jsx +++ b/pkg/shell/hosts.jsx @@ -70,7 +70,7 @@ export class CockpitHosts extends React.Component { componentDidMount() { cockpit.user().then(user => { this.setState({ current_user: user.name || "" }); - }); + }).catch(exc => console.log(exc)); } static getDerivedStateFromProps(nextProps, prevState) { diff --git a/pkg/shell/indexes.jsx b/pkg/shell/indexes.jsx index 26397654361..1b744a21fbe 100644 --- a/pkg/shell/indexes.jsx +++ b/pkg/shell/indexes.jsx @@ -97,7 +97,7 @@ function MachinesIndex(index_options, machines, loader) { let current_user = ""; cockpit.user().then(user => { current_user = user.name || ""; - }); + }).catch(exc => console.log(exc)); /* Navigation */ let ready = false;