Chore: Log error from App loading in console and faro (#79977)

* Chore: Log error from App loading in console and faro

* Add error spy for console
This commit is contained in:
Esteban Beltran 2024-01-03 15:51:31 +01:00 committed by GitHub
parent c219a19f97
commit 5c67c4b082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -103,9 +103,12 @@ describe('AppRootPage', () => {
});
it("should show a not found page if the plugin settings can't load", async () => {
jest.spyOn(console, 'error').mockImplementation();
getPluginSettingsMock.mockRejectedValue(new Error('Unknown Plugin'));
// Renders once for the first time
await renderUnderRouter();
await act(async () => {
await renderUnderRouter();
});
expect(await screen.findByText('App not found')).toBeVisible();
});

View File

@ -13,7 +13,7 @@ import {
PluginType,
PluginContextProvider,
} from '@grafana/data';
import { config, locationSearchToObject } from '@grafana/runtime';
import { config, locationSearchToObject, logError } from '@grafana/runtime';
import { Alert } from '@grafana/ui';
import { Page } from 'app/core/components/Page/Page';
import PageLoader from 'app/core/components/PageLoader/PageLoader';
@ -21,6 +21,7 @@ import { EntityNotFound } from 'app/core/components/PageNotFound/EntityNotFound'
import { useGrafana } from 'app/core/context/GrafanaContext';
import { appEvents, contextSrv } from 'app/core/core';
import { getNotFoundNav, getWarningNav, getExceptionNav } from 'app/core/navigation/errorModels';
import { getMessageFromError } from 'app/core/utils/errors';
import { getPluginSettings } from '../pluginSettings';
import { importAppPlugin } from '../plugin_loader';
@ -191,6 +192,9 @@ async function loadAppPlugin(pluginId: string, dispatch: React.Dispatch<AnyActio
pluginNav: process.env.NODE_ENV === 'development' ? getExceptionNav(err) : getNotFoundNav(),
})
);
const error = err instanceof Error ? err : new Error(getMessageFromError(err));
logError(error);
console.error(error);
}
}