mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 10:35:11 +00:00
proper error handling for compiler error
This commit is contained in:
@@ -34,7 +34,7 @@ import {
|
||||
programResponse,
|
||||
rebootRequest,
|
||||
} from '../actions/lwp3-bootloader';
|
||||
import { didCompile } from '../actions/mpy';
|
||||
import { didCompile, didFailToCompile } from '../actions/mpy';
|
||||
import { HubType, Result } from '../protocols/lwp3-bootloader';
|
||||
import { createCountFunc } from '../utils/iter';
|
||||
import flashFirmware from './flash-firmware';
|
||||
@@ -411,6 +411,61 @@ describe('flashFirmware', () => {
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
|
||||
test('compile error', async () => {
|
||||
const metadata: FirmwareMetadata = {
|
||||
'metadata-version': '1.0.0',
|
||||
'device-id': HubType.MoveHub,
|
||||
'checksum-type': 'sum',
|
||||
'firmware-version': '1.2.3',
|
||||
'max-firmware-size': 1024,
|
||||
'mpy-abi-version': 5,
|
||||
'mpy-cross-options': ['-mno-unicode'],
|
||||
'user-mpy-offset': 100,
|
||||
};
|
||||
|
||||
const zip = new JSZip();
|
||||
zip.file('firmware-base.bin', new Uint8Array(64));
|
||||
zip.file('firmware.metadata.json', JSON.stringify(metadata));
|
||||
zip.file('main.py', 'print("test")');
|
||||
zip.file('ReadMe_OSS.txt', 'test');
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
saga.setState({ settings: { flashCurrentProgram: false } });
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(
|
||||
flashFirmwareAction(await zip.generateAsync({ type: 'arraybuffer' })),
|
||||
);
|
||||
|
||||
// the first step is to compile main.py to .mpy
|
||||
|
||||
let action = await saga.take();
|
||||
expect(action).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"options": Array [
|
||||
"-mno-unicode",
|
||||
],
|
||||
"script": "print(\\"test\\")",
|
||||
"type": "mpy.action.compile",
|
||||
}
|
||||
`);
|
||||
|
||||
saga.put(didFailToCompile(['test']));
|
||||
|
||||
// compiler error should trigger firmware flash failure
|
||||
|
||||
action = await saga.take();
|
||||
expect(action).toEqual(
|
||||
didFailToStart(FailToStartReasonType.FailedToCompile),
|
||||
);
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('user supplied main.py', async () => {
|
||||
|
||||
@@ -109,7 +109,10 @@ function* firmwareIterator(data: DataView, maxSize: number): Generator<number> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads Pybricks firmware from a .zip file
|
||||
* Loads Pybricks firmware from a .zip file.
|
||||
*
|
||||
* This can raise didFailToStart() actions, so don't call this after didStart().
|
||||
*
|
||||
* @param data The zip file raw data
|
||||
* @param program User program or `undefined` to use main.py from firmware.zip
|
||||
*/
|
||||
@@ -157,7 +160,8 @@ function* loadFirmware(
|
||||
});
|
||||
|
||||
if (mpyFail) {
|
||||
throw Error(mpyFail.err.join('\n'));
|
||||
yield* put(didFailToStart(FailToStartReasonType.FailedToCompile));
|
||||
yield* cancel();
|
||||
}
|
||||
|
||||
defined(mpy);
|
||||
|
||||
Reference in New Issue
Block a user