show more error popups for usb connection by dlech · Pull Request #2362 · pybricks/pybricks-code · GitHub
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
8 changes: 6 additions & 2 deletions src/alerts/UnexpectedErrorAlert.tsx
2 changes: 1 addition & 1 deletion src/alerts/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"message": "An unexpected error occurred. Please consider reporting this so we can make a better error message.",
"message": "An unexpected error occurred. Please consider reporting this so we can make a better error message. Click the {copyErrorMessage} button below to copy the technical details and paste it in the bug report. Also include the operating system you are using, the web browser you are using and the actions you performed that led to this error.",
"technicalInfo": "Expand for detailed technical information",
"copyErrorMessage": "Copy Error Message",
"reportBug": "Report Bug"
Expand Down
19 changes: 19 additions & 0 deletions src/usb/alerts/AccessDenied.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025-2026 The Pybricks Authors

import { Toast } from '@blueprintjs/core';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import { accessDenied } from './AccessDenied';

it('should dismiss when close is clicked', async () => {
const callback = jest.fn();
const toast = accessDenied(callback, undefined as never);

const [user, message] = testRender(<Toast {...toast} />);

await act(() => user.click(message.getByRole('button', { name: /close/i })));

expect(callback).toHaveBeenCalledWith('dismiss');
});
26 changes: 26 additions & 0 deletions src/usb/alerts/AccessDenied.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025-2026 The Pybricks Authors

import { Intent } from '@blueprintjs/core';
import { Error } from '@blueprintjs/icons';
import React from 'react';
import type { CreateToast } from '../../toasterTypes';
import { isLinux } from '../../utils/os';
import { useI18n } from './i18n';

const AccessDenied: React.FunctionComponent = () => {
const i18n = useI18n();
return (
<>
<p>{i18n.translate('accessDenied.message')}</p>
{isLinux() && <p>{i18n.translate('accessDenied.linuxSuggestion')}</p>}
</>
);
};

export const accessDenied: CreateToast = (onAction) => ({
message: <AccessDenied />,
icon: <Error />,
intent: Intent.DANGER,
onDismiss: () => onAction('dismiss'),
});
19 changes: 19 additions & 0 deletions src/usb/alerts/AlreadyInUse.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025-2026 The Pybricks Authors

import { Toast } from '@blueprintjs/core';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import { alreadyInUse } from './AlreadyInUse';

it('should dismiss when close is clicked', async () => {
const callback = jest.fn();
const toast = alreadyInUse(callback, undefined as never);

const [user, message] = testRender(<Toast {...toast} />);

await act(() => user.click(message.getByRole('button', { name: /close/i })));

expect(callback).toHaveBeenCalledWith('dismiss');
});
24 changes: 24 additions & 0 deletions src/usb/alerts/AlreadyInUse.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025-2026 The Pybricks Authors

import { Intent } from '@blueprintjs/core';
import { Error } from '@blueprintjs/icons';
import React from 'react';
import type { CreateToast } from '../../toasterTypes';
import { useI18n } from './i18n';

const AlreadyInUse: React.FunctionComponent = () => {
const i18n = useI18n();
return (
<>
<p>{i18n.translate('alreadyInUse.message')}</p>
</>
);
};

export const alreadyInUse: CreateToast = (onAction) => ({
message: <AlreadyInUse />,
icon: <Error />,
intent: Intent.DANGER,
onDismiss: () => onAction('dismiss'),
});
6 changes: 5 additions & 1 deletion src/usb/alerts/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025 The Pybricks Authors
// Copyright (c) 2025-2026 The Pybricks Authors

import { accessDenied } from './AccessDenied';
import { alreadyInUse } from './AlreadyInUse';
import { newPybricksProfile } from './NewPybricksProfile';
import { noWebUsb } from './NoWebUsb';
import { oldFirmware } from './OldFirmware';

// gathers all of the alert creation functions for passing up to the top level
export default {
accessDenied,
alreadyInUse,
newPybricksProfile,
noWebUsb,
oldFirmware,
Expand Down
7 changes: 7 additions & 0 deletions src/usb/alerts/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"suggestion": "Use a supported browser such as Google Chrome or Microsoft Edge.",
"action": "More Info"
},
"accessDenied": {
"message": "Access to the USB device was denied.",
"linuxSuggestion": "On Linux, ensure that you have the correct udev rules installed."
},
"alreadyInUse": {
"message": "This hub is already in use by another application."
},
"oldFirmware": {
"message": "A new firmware version is available for this hub. Please install the latest version to use all new features.",
"flashFirmware": {
Expand Down
62 changes: 54 additions & 8 deletions src/usb/sagas.ts