From f11156db5bd3bbc59eb3f5a3b644df64e4ab818d Mon Sep 17 00:00:00 2001 From: Evgeny Kochetkov Date: Fri, 23 Nov 2018 19:23:38 +0300 Subject: [PATCH] fix(xod-arduino, xod-client): add missing formatter for error about too many outputs Closes #1545 --- packages/xod-arduino/src/index.js | 2 ++ packages/xod-arduino/src/messages.js | 10 ++++++++++ packages/xod-arduino/src/transpiler.js | 11 ++++------- packages/xod-arduino/test/transpiler.spec.js | 6 ++++-- packages/xod-client/src/core/formatErrorMessage.js | 2 ++ 5 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 packages/xod-arduino/src/messages.js diff --git a/packages/xod-arduino/src/index.js b/packages/xod-arduino/src/index.js index f25a1bdb..621466a5 100644 --- a/packages/xod-arduino/src/index.js +++ b/packages/xod-arduino/src/index.js @@ -5,3 +5,5 @@ export { getNodeIdsMap, getRequireUrls, } from './transpiler'; + +export { default as messages } from './messages'; diff --git a/packages/xod-arduino/src/messages.js b/packages/xod-arduino/src/messages.js new file mode 100644 index 00000000..4703abd1 --- /dev/null +++ b/packages/xod-arduino/src/messages.js @@ -0,0 +1,10 @@ +// Stanza creators. +// See `xod-func-tools` package Stanza type +export default { + TOO_MANY_OUTPUTS_FOR_NATIVE_NODE: ({ patchPath }) => ({ + title: 'Too many outputs', + note: `C++ node ${patchPath} has more than 7 outputs. This is a limit for nodes implemented natively.`, + solution: + 'Try to express the node as a XOD patch node composed of smaller C++ nodes or group the outputs into a new custom type.', + }), +}; diff --git a/packages/xod-arduino/src/transpiler.js b/packages/xod-arduino/src/transpiler.js index 7e767434..708e9601 100644 --- a/packages/xod-arduino/src/transpiler.js +++ b/packages/xod-arduino/src/transpiler.js @@ -7,6 +7,7 @@ import { maybeProp, foldEither, isAmong, + fail, } from 'xod-func-tools'; import * as XP from 'xod-project'; import { def } from './types'; @@ -425,13 +426,9 @@ const checkForNativePatchesWithTooManyOutputs = def( ); if (nodeWithTooManyOutputs) { - return Either.Left( - new Error( - `Native node ${ - nodeWithTooManyOutputs.patchPath - } has more than 7 outputs` - ) - ); + return fail('TOO_MANY_OUTPUTS_FOR_NATIVE_NODE', { + patchPath: nodeWithTooManyOutputs.patchPath, + }); } return Either.of(tProject); diff --git a/packages/xod-arduino/test/transpiler.spec.js b/packages/xod-arduino/test/transpiler.spec.js index 8f0bd2ce..259d8245 100644 --- a/packages/xod-arduino/test/transpiler.spec.js +++ b/packages/xod-arduino/test/transpiler.spec.js @@ -57,8 +57,10 @@ describe('xod-arduino transpiler', () => { .then( foldEither( err => { - assert.include(err.message, '@/too-many-outputs'); - assert.include(err.message, 'has more than 7 outputs'); + assert.strictEqual( + err.message, + 'TOO_MANY_OUTPUTS_FOR_NATIVE_NODE {"patchPath":"@/too-many-outputs"}' + ); }, () => assert(false, 'expecting Either.Left') ) diff --git a/packages/xod-client/src/core/formatErrorMessage.js b/packages/xod-client/src/core/formatErrorMessage.js index 55b8a3b3..5a4c5402 100644 --- a/packages/xod-client/src/core/formatErrorMessage.js +++ b/packages/xod-client/src/core/formatErrorMessage.js @@ -1,10 +1,12 @@ import { composeErrorFormatters } from 'xod-func-tools'; import { messages as xpMessages } from 'xod-project'; +import { messages as xardMessages } from 'xod-arduino'; import formatUnexpectedError from '../messages/formatUnexpectedError'; export default composeErrorFormatters([ xpMessages, + xardMessages, { UNEXPECTED_ERROR: formatUnexpectedError, },