diff --git a/craco.config.js b/craco.config.js index 4da4d1dc..05312466 100644 --- a/craco.config.js +++ b/craco.config.js @@ -111,7 +111,6 @@ SOFTWARE.`; const licenseTextOverrides = { '@pybricks/firmware': pybricksLicense, - '@pybricks/mpy-cross-v5': pybricksLicense, '@shopify/dates': shopifyLicense, '@shopify/decorators': shopifyLicense, '@shopify/function-enhancers': shopifyLicense, diff --git a/package.json b/package.json index aba96565..892bd861 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "@blueprintjs/core": "^3.36.0", "@craco/craco": "^6.0.0", "@pybricks/firmware": "4.4.0", - "@pybricks/mpy-cross-v5": "^1.2.0", + "@pybricks/mpy-cross-v5": "^2.0.0", "@shopify/react-i18n": "^5.2.0", "@testing-library/dom": "^7.29.2", "@testing-library/jest-dom": "^5.11.8", diff --git a/src/actions/mpy.ts b/src/actions/mpy.ts index 7f34be36..7663f295 100644 --- a/src/actions/mpy.ts +++ b/src/actions/mpy.ts @@ -32,10 +32,10 @@ export function didCompile(data: Uint8Array): MpyDidCompileAction { export type MpyDidFailToCompileAction = Action & { /** Error output. */ - readonly err: string; + readonly err: string[]; }; -export function didFailToCompile(err: string): MpyDidFailToCompileAction { +export function didFailToCompile(err: string[]): MpyDidFailToCompileAction { return { type: MpyActionType.DidFailToCompile, err }; } diff --git a/src/sagas/__snapshots__/mpy.test.ts.snap b/src/sagas/__snapshots__/mpy.test.ts.snap new file mode 100644 index 00000000..1e4167cd --- /dev/null +++ b/src/sagas/__snapshots__/mpy.test.ts.snap @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`compiler error works 1`] = ` +Array [ + "Traceback (most recent call last):", + " File \\"main.py\\", line 1", + "SyntaxError: invalid syntax", +] +`; diff --git a/src/sagas/flash-firmware.ts b/src/sagas/flash-firmware.ts index bb095420..f80d6c8d 100644 --- a/src/sagas/flash-firmware.ts +++ b/src/sagas/flash-firmware.ts @@ -146,7 +146,7 @@ function* loadFirmware( ])) as [MpyDidCompileAction, MpyDidFailToCompileAction]; if (mpyFail) { - throw Error(mpyFail.err); + throw Error(mpyFail.err.join('\n')); } // compute offset for checksum - must be aligned to 4-byte boundary diff --git a/src/sagas/mpy.test.ts b/src/sagas/mpy.test.ts index b4d81493..141a0f62 100644 --- a/src/sagas/mpy.test.ts +++ b/src/sagas/mpy.test.ts @@ -37,7 +37,7 @@ test('compiler error works', async () => { const action = await saga.take(); expect(action.type).toBe(MpyActionType.DidFailToCompile); const { err } = action as MpyDidFailToCompileAction; - expect(err).toContain('SyntaxError'); + expect(err).toMatchSnapshot(); await saga.end(); }); diff --git a/src/sagas/notification.test.ts b/src/sagas/notification.test.ts index 86212272..5ffd07f1 100644 --- a/src/sagas/notification.test.ts +++ b/src/sagas/notification.test.ts @@ -31,7 +31,7 @@ test.each([ bootloaderDidFailToConnect(BootloaderConnectionFailureReason.NoWebBluetooth), bootloaderDidFailToConnect(BootloaderConnectionFailureReason.GattServiceNotFound), storageChanged('test'), - didFailToCompile('reason'), + didFailToCompile(['reason']), add('warning', 'message'), add('error', 'message', 'url'), didUpdate({} as ServiceWorkerRegistration), diff --git a/src/sagas/notification.ts b/src/sagas/notification.ts index 47ee3e5c..d386583b 100644 --- a/src/sagas/notification.ts +++ b/src/sagas/notification.ts @@ -220,7 +220,9 @@ function* dismissCompilerError(): Generator { } function* showCompilerError(action: MpyDidFailToCompileAction): Generator { - yield* showSingleton(Level.Error, MessageId.MpyError, { errorMessage: action.err }); + yield* showSingleton(Level.Error, MessageId.MpyError, { + errorMessage: React.createElement('pre', undefined, action.err.join('\n')), + }); } function* addNotification(action: NotificationAddAction): Generator { diff --git a/yarn.lock b/yarn.lock index 4018380f..c6a9ebcc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1462,10 +1462,10 @@ dependencies: jszip "^3.5.0" -"@pybricks/mpy-cross-v5@^1.2.0": - version "1.2.0" - resolved "https://registry.yarnpkg.com/@pybricks/mpy-cross-v5/-/mpy-cross-v5-1.2.0.tgz#29cbd949c579c0551792d2fd1cd777d193aa925c" - integrity sha512-A1FXGP0teuZa3tPBTz9niCdEol4Ld6jOABl9FkglmutGWO99eLwuyYibh8wQqHNKwXRHrzCJmo/W+/42HmSjog== +"@pybricks/mpy-cross-v5@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@pybricks/mpy-cross-v5/-/mpy-cross-v5-2.0.0.tgz#9d64e1dedda0a7a028117f510ce5365f504df400" + integrity sha512-s3B+0tsXRHF3Y+FfOeDkNLoM+dwwT8P05UowVYPQvTV/UjhBGwruUdEoG/cYz2cFrqx+VFF8gpgmpw+5aA7/hQ== "@redux-saga/core@^1.1.3": version "1.1.3"