mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
ble/sagas: move console logging to saga
This commit is contained in:
@@ -385,6 +385,12 @@ function* handleBleConnectPybricks(): Generator {
|
||||
|
||||
yield* put(bleDidDisconnectPybricks());
|
||||
} catch (err) {
|
||||
// istanbul ignore if
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
// log error so it can still be copied even if alert is closed
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
yield* put(
|
||||
alertsShowAlert('alerts', 'unexpectedError', {
|
||||
error: ensureError(err),
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
import { AsyncSaga } from '../../test';
|
||||
import { didFailToWrite } from '../ble-nordic-uart-service/actions';
|
||||
import { eventProtocolError } from '../ble-pybricks-service/actions';
|
||||
import {
|
||||
BleDeviceFailToConnectReasonType,
|
||||
bleDidFailToConnectPybricks,
|
||||
} from '../ble/actions';
|
||||
import {
|
||||
BootloaderConnectionFailureReason,
|
||||
didError,
|
||||
@@ -15,29 +11,6 @@ import {
|
||||
} from '../lwp3-bootloader/actions';
|
||||
import errorLog from './sagas';
|
||||
|
||||
test('bleDeviceDidFailToConnect', async () => {
|
||||
const saga = new AsyncSaga(errorLog);
|
||||
|
||||
console.error = jest.fn();
|
||||
|
||||
saga.put(
|
||||
bleDidFailToConnectPybricks({
|
||||
reason: BleDeviceFailToConnectReasonType.Canceled,
|
||||
}),
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledTimes(0);
|
||||
|
||||
saga.put(
|
||||
bleDidFailToConnectPybricks({
|
||||
reason: BleDeviceFailToConnectReasonType.Unknown,
|
||||
err: new Error('test error'),
|
||||
}),
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
|
||||
test('bleDataDidFailToWrite', async () => {
|
||||
const saga = new AsyncSaga(errorLog);
|
||||
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
import { takeEvery } from 'typed-redux-saga/macro';
|
||||
import { didFailToWrite as bleUartDidFailToWrite } from '../ble-nordic-uart-service/actions';
|
||||
import { eventProtocolError as pybricksEventProtocolError } from '../ble-pybricks-service/actions';
|
||||
import {
|
||||
BleDeviceFailToConnectReasonType,
|
||||
bleDidFailToConnectPybricks,
|
||||
} from '../ble/actions';
|
||||
import { fileStorageDidFailToStoreTextFileValue } from '../fileStorage/actions';
|
||||
import {
|
||||
BootloaderConnectionFailureReason,
|
||||
@@ -15,14 +11,6 @@ import {
|
||||
didFailToConnect as bootloaderDidFailToConnect,
|
||||
} from '../lwp3-bootloader/actions';
|
||||
|
||||
function handleBleDeviceDidFailToConnect(
|
||||
action: ReturnType<typeof bleDidFailToConnectPybricks>,
|
||||
): void {
|
||||
if (action.reason === BleDeviceFailToConnectReasonType.Unknown) {
|
||||
console.error(action.err);
|
||||
}
|
||||
}
|
||||
|
||||
function handlePybricksEventProtocolError(
|
||||
action: ReturnType<typeof pybricksEventProtocolError>,
|
||||
): void {
|
||||
@@ -54,7 +42,6 @@ function handleFileStorageDidFailToStoreTextFileValue(
|
||||
}
|
||||
|
||||
export default function* (): Generator {
|
||||
yield* takeEvery(bleDidFailToConnectPybricks, handleBleDeviceDidFailToConnect);
|
||||
yield* takeEvery(pybricksEventProtocolError, handlePybricksEventProtocolError);
|
||||
yield* takeEvery(bleUartDidFailToWrite, handleBleUartDidFailToWrite);
|
||||
yield* takeEvery(bootloaderDidFailToConnect, handleBootloaderDidFailToConnect);
|
||||
|
||||
Reference in New Issue
Block a user