Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.3.13/schema.json",
"$schema": "https://biomejs.dev/schemas/2.4.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { clientApi } from '../../pages/client/clientAPI/clientApi.ts';
import { useClientStore } from '../../pages/client/hooks/useClientStore';
import { TauriEventKey } from '../../pages/client/types';
import type { NewApplicationVersionInfo } from '../../shared/hooks/api/types';
import { errorDetail } from '../../shared/utils/errorDetail';
import {
type ApplicationUpdateStore,
useApplicationUpdateStore,
Expand Down Expand Up @@ -83,7 +84,8 @@ export const ApplicationUpdateManager = () => {
dismissed: false,
});
} catch (e) {
error(`Failed to check latest app version: ${e}`);
const detail = errorDetail(e);
error(`Failed to check latest app version (current: ${appVersion}): ${detail}`);
}
};

Expand Down
4 changes: 3 additions & 1 deletion src/components/AutoProvisioningManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { ProvisioningConfig } from '../pages/client/clientAPI/types';
import { clientQueryKeys } from '../pages/client/query';
import { useToaster } from '../shared/defguard-ui/hooks/toasts/useToaster';
import useAddInstance from '../shared/hooks/useAddInstance';
import { errorDetail } from '../shared/utils/errorDetail';

const { getProvisioningConfig } = clientApi;

Expand All @@ -26,8 +27,9 @@ export default function AutoProvisioningManager({ children }: PropsWithChildren)
token: config.enrollment_token,
});
} catch (e) {
const detail = errorDetail(e);
error(
`Failed to handle automatic client provisioning with ${JSON.stringify(config)}.\n Error: ${JSON.stringify(e)}`,
`Failed to handle automatic client provisioning (url: ${config.enrollment_url}): ${detail}`,
);
toaster.error(
'Automatic client provisioning failed, please contact your administrator.',
Expand Down
15 changes: 15 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { error } from '@tauri-apps/plugin-log';
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';

import { App } from './components/App/App';
import { errorDetail } from './shared/utils/errorDetail';

// Forward uncaught JS errors to the Tauri backend log
window.onerror = (message, source, lineno, colno, err) => {
const detail = err?.stack ?? `${message} (${source}:${lineno}:${colno})`;
error(`[uncaught error] ${detail}`);
// returning false lets the error propagate to the browser DevTools console
return false;
};

// Forward unhandled promise rejections to the Tauri backend log
window.addEventListener('unhandledrejection', (event) => {
error(`[unhandled rejection] ${errorDetail(event.reason)}`);
});

const rootElement = document.getElementById('root') as HTMLElement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
CreateDeviceResponse,
} from '../../../../../../../../shared/hooks/api/types';
import { routes } from '../../../../../../../../shared/routes';
import { errorDetail } from '../../../../../../../../shared/utils/errorDetail';
import { generateWGKeys } from '../../../../../../../../shared/utils/generateWGKeys';
import { clientApi } from '../../../../../../clientAPI/clientApi';
import { useClientStore } from '../../../../../../hooks/useClientStore';
Expand Down Expand Up @@ -134,6 +135,8 @@ export const AddInstanceDeviceForm = () => {
navigate(routes.client.instancePage, { replace: true });
})
.catch((e) => {
const detail = errorDetail(e);
error(`Failed to save device config: ${detail}`);
toaster.error(
LL.common.messages.errorWithMessage({
message: String(e),
Expand All @@ -144,7 +147,8 @@ export const AddInstanceDeviceForm = () => {
});
} catch (e) {
setIsLoading(false);
console.error(e);
const detail = errorDetail(e);
error(`Device form submit failed for proxy ${proxyUrl}: ${detail}`);

if (typeof e === 'string') {
if (e.includes('Network Error')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useMemo, useState } from 'react';
import { type SubmitHandler, useForm } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';
import { z } from 'zod';

import { useI18nContext } from '../../../../../../../../i18n/i18n-react';
import { FormInput } from '../../../../../../../../shared/defguard-ui/components/Form/FormInput/FormInput';
import { Button } from '../../../../../../../../shared/defguard-ui/components/Layout/Button/Button';
Expand All @@ -24,6 +23,7 @@ import type {
EnrollmentStartResponse,
} from '../../../../../../../../shared/hooks/api/types';
import { routes } from '../../../../../../../../shared/routes';
import { errorDetail } from '../../../../../../../../shared/utils/errorDetail';
import { useEnrollmentStore } from '../../../../../../../enrollment/hooks/store/useEnrollmentStore';
import { clientApi } from '../../../../../../clientAPI/clientApi';
import { useClientStore } from '../../../../../../hooks/useClientStore';
Expand Down Expand Up @@ -96,7 +96,9 @@ export const AddInstanceInitForm = () => {
.then(async (res: Response) => {
if (!res.ok) {
setIsLoading(false);
error(JSON.stringify(res.status));
error(
`Enrollment start returned non-OK status ${res.status} for URL: ${endpointUrl}`,
);
const errorMessage = ((await res.json()) as EnrollmentError).error;

switch (errorMessage) {
Expand All @@ -120,9 +122,7 @@ export const AddInstanceInitForm = () => {
if (!authCookie) {
setIsLoading(false);
error(
LL.common.messages.errorWithMessage({
message: LL.common.messages.noCookie(),
}),
`Enrollment start response for ${endpointUrl} is missing defguard_proxy set-cookie header`,
);
throw Error(
LL.common.messages.errorWithMessage({
Expand Down Expand Up @@ -154,34 +154,57 @@ export const AddInstanceInitForm = () => {
body: JSON.stringify({
pubkey: instance.pubkey,
}),
}).then(async (res) => {
invoke<void>('update_instance', {
instanceId: instance.id,
response: (await res.json()) as CreateDeviceResponse,
})
.then(() => {
info('Configured device');
toaster.success(
LL.pages.enrollment.steps.deviceSetup.desktopSetup.messages.deviceConfigured(),
);
const _selectedInstance: SelectedInstance = {
id: instance.id,
type: ClientConnectionType.LOCATION,
};
setClientState({
selectedInstance: _selectedInstance,
});
navigate(routes.client.base, { replace: true });
})
.catch((e) => {
error(e);
})
.then(async (res) => {
if (!res.ok) {
const detail = `network_info returned status ${res.status} for instance ${instance.uuid}`;
error(`Failed to fetch network info: ${detail}`);
toaster.error(
LL.common.messages.errorWithMessage({
message: String(e),
message: detail,
}),
);
});
});
return;
}
invoke<void>('update_instance', {
instanceId: instance.id,
response: (await res.json()) as CreateDeviceResponse,
})
.then(() => {
info('Configured device');
toaster.success(
LL.pages.enrollment.steps.deviceSetup.desktopSetup.messages.deviceConfigured(),
);
const _selectedInstance: SelectedInstance = {
id: instance.id,
type: ClientConnectionType.LOCATION,
};
setClientState({
selectedInstance: _selectedInstance,
});
navigate(routes.client.base, { replace: true });
})
.catch((e) => {
const detail = errorDetail(e);
error(`Failed to save config during instance add: ${detail}`);
toaster.error(
LL.common.messages.errorWithMessage({
message: String(e),
}),
);
});
})
.catch((e) => {
const detail = errorDetail(e);
error(
`Failed to reach network_info endpoint for instance ${instance.uuid}: ${detail}`,
);
toaster.error(
LL.common.messages.errorWithMessage({
message: String(e),
}),
);
});
}
// register new instance
// is user in need of full enrollment ?
Expand Down Expand Up @@ -220,6 +243,8 @@ export const AddInstanceInitForm = () => {
})
.catch((e) => {
setIsLoading(false);
const detail = errorDetail(e);
error(`Failed to initialize instance: ${detail}`);
if (typeof e === 'string') {
if (e.includes('Network Error')) {
toaster.error(LL.common.messages.networkError());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { zodResolver } from '@hookform/resolvers/zod';
import { error } from '@tauri-apps/plugin-log';
import { useMemo, useState } from 'react';
import { type SubmitHandler, useForm } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';
import { z } from 'zod';

import { useI18nContext } from '../../../../../i18n/i18n-react';
import { FormInput } from '../../../../../shared/defguard-ui/components/Form/FormInput/FormInput';
import { ArrowSingle } from '../../../../../shared/defguard-ui/components/icons/ArrowSingle/ArrowSingle';
Expand All @@ -23,6 +23,7 @@ import {
patternValidWireguardKey,
} from '../../../../../shared/patterns';
import { routes } from '../../../../../shared/routes';
import { errorDetail } from '../../../../../shared/utils/errorDetail';
import { validateIpOrDomainList } from '../../../../../shared/validators/tunnel';
import { clientApi } from '../../../clientAPI/clientApi';
import type { Tunnel } from '../../../types';
Expand Down Expand Up @@ -197,9 +198,11 @@ export const EditTunnelFormCard = ({ tunnel, submitRef }: Props) => {
navigate(routes.client.base, { replace: true });
toaster.success(LL.pages.client.pages.editTunnelPage.messages.editSuccess());
})
.catch(() =>
toaster.error(LL.pages.client.pages.editTunnelPage.messages.editError()),
);
.catch((e) => {
const detail = errorDetail(e);
error(`Failed to update tunnel: ${detail}`);
toaster.error(LL.pages.client.pages.editTunnelPage.messages.editError());
});
};

const { handleSubmit, control } = useForm<Tunnel>({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { error } from '@tauri-apps/plugin-log';
import { isUndefined } from 'lodash-es';
import { useNavigate } from 'react-router-dom';
import { shallow } from 'zustand/shallow';

import { useI18nContext } from '../../../../../../i18n/i18n-react';
import { ConfirmModal } from '../../../../../../shared/defguard-ui/components/Layout/modals/ConfirmModal/ConfirmModal';
import { ConfirmModalType } from '../../../../../../shared/defguard-ui/components/Layout/modals/ConfirmModal/types';
import { useToaster } from '../../../../../../shared/defguard-ui/hooks/toasts/useToaster';
import { routes } from '../../../../../../shared/routes';
import { errorDetail } from '../../../../../../shared/utils/errorDetail';
import { clientApi } from '../../../../clientAPI/clientApi';
import { useClientStore } from '../../../../hooks/useClientStore';
import { clientQueryKeys } from '../../../../query';
Expand Down Expand Up @@ -59,7 +60,8 @@ export const DeleteTunnelModal = () => {
message: String(e),
}),
);
console.error(e);
const detail = errorDetail(e);
error(`Failed to delete tunnel "${tunnel?.name}" (id: ${tunnel?.id}): ${detail}`);
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import './style.scss';
import { error } from '@tauri-apps/plugin-log';
import classNames from 'classnames';
import { useState } from 'react';

import { useI18nContext } from '../../../../../../../../i18n/i18n-react';
import SvgIconCheckmarkSmall from '../../../../../../../../shared/components/svg/IconCheckmarkSmall';
import { Button } from '../../../../../../../../shared/defguard-ui/components/Layout/Button/Button';
Expand All @@ -13,6 +12,7 @@ import {
} from '../../../../../../../../shared/defguard-ui/components/Layout/Button/types';
import SvgIconX from '../../../../../../../../shared/defguard-ui/components/svg/IconX';
import { useToaster } from '../../../../../../../../shared/defguard-ui/hooks/toasts/useToaster';
import { errorDetail } from '../../../../../../../../shared/utils/errorDetail';
import { clientApi } from '../../../../../../clientAPI/clientApi';
import { type CommonWireguardFields, LocationMfaType } from '../../../../../../types';
import { useMFAModal } from '../../modals/MFAModal/useMFAModal';
Expand Down Expand Up @@ -66,8 +66,10 @@ export const LocationCardConnectButton = ({ location }: Props) => {
message: String(e),
}),
);
error(`Error handling interface: ${e}`);
console.error(e);
const detail = errorDetail(e);
error(
`Error handling interface for location ${location?.id} (${location?.active ? 'disconnect' : 'connect'}): ${detail}`,
);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useMemo } from 'react';
import { useI18nContext } from '../../../../../../../../i18n/i18n-react';
import { Toggle } from '../../../../../../../../shared/defguard-ui/components/Layout/Toggle/Toggle';
import type { ToggleOption } from '../../../../../../../../shared/defguard-ui/components/Layout/Toggle/types';
import { errorDetail } from '../../../../../../../../shared/utils/errorDetail';
import { clientApi } from '../../../../../../clientAPI/clientApi';
import {
ClientConnectionType,
Expand All @@ -30,8 +31,10 @@ export const LocationCardRoute = ({ location, selectedDefguardInstance }: Props)
});
}
} catch (e) {
error(`Error handling routing: ${e}`);
console.error(e);
const detail = errorDetail(e);
error(
`Failed to update routing for location ${location?.id} (type: ${location?.connection_type}, routeAllTraffic: ${value}): ${detail}`,
);
}
};

Expand Down
Loading
Loading