@cumulus/cumulus-message-adapter-js
Advanced tools
Comparing version
@@ -9,2 +9,8 @@ # Changelog | ||
## [v1.1.1] - 2020-01-15 | ||
### Fixed | ||
- **CUMULUS-1708** - Fixed issue with CMA stderr/stdout being suppressed | ||
## [v1.1.0] - 2019-12-12 | ||
@@ -11,0 +17,0 @@ |
32
index.js
@@ -21,21 +21,26 @@ 'use strict'; | ||
/** | ||
* Invoke the cumulus-message-adapter | ||
* Generates CMA command line arguments | ||
* | ||
* @param {string} command - the action to be performed by the message-adapter | ||
* @param {Object} input - the input to be sent to the message-adapter | ||
* @returns {Promise.<Object>} - the output of the message-adapter | ||
* @returns {Promise.<Array>} - Returns arguments used to spawn the CMA | ||
*/ | ||
async function callCumulusMessageAdapter(command, input) { | ||
async function generateCMASpawnArguments(command) { | ||
const adapterDir = process.env.CUMULUS_MESSAGE_ADAPTER_DIR || './cumulus-message-adapter'; | ||
const systemPython = await lookpath('python'); | ||
let spawnArguments; | ||
if (systemPython) { | ||
spawnArguments = [systemPython, [`${adapterDir}`, command]]; | ||
return [systemPython, [`${adapterDir}`, command]]; | ||
} | ||
else { | ||
// If there is no system python, attempt use of pre-packaged CMA binary | ||
spawnArguments = [`${adapterDir}/cma`, [command]]; | ||
} | ||
// If there is no system python, attempt use of pre-packaged CMA binary | ||
return [`${adapterDir}/cma`, [command]]; | ||
} | ||
/** | ||
* Invoke the cumulus-message-adapter | ||
* | ||
* @param {string} command - the action to be performed by the message-adapter | ||
* @param {Object} input - the input to be sent to the message-adapter | ||
* @returns {Promise.<Object>} - the output of the message-adapter | ||
*/ | ||
async function callCumulusMessageAdapter(command, input) { | ||
const spawnArguments = await generateCMASpawnArguments(command); | ||
try { | ||
@@ -50,4 +55,5 @@ const cumulusMessageAdapter = execa(...spawnArguments); | ||
catch (error) { | ||
const msg = `CMA process failed to run, check that python runtime is present in the path and/or | ||
the CMA package is present in ${adapterDir}. Error: ${error}`; | ||
const msg = `CMA process failed (${error.shortMessage})\n | ||
Trace: ${error.message}}\n\n\n | ||
STDERR: ${error.stderr}`; | ||
throw new CumulusMessageAdapterExecutionError(msg); | ||
@@ -54,0 +60,0 @@ } |
{ | ||
"name": "@cumulus/cumulus-message-adapter-js", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Cumulus message adapter", | ||
@@ -54,3 +54,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"execa": "^3.4.0", | ||
"execa": "^4.0.0", | ||
"lodash.get": "^4.4.2", | ||
@@ -57,0 +57,0 @@ "lookpath": "1.0.3" |
@@ -9,3 +9,3 @@ /* eslint-disable no-param-reassign */ | ||
const cumulusMessageAdapter = require('../index'); | ||
const cumulusMessageAdapter = rewire('../index'); | ||
const { downloadCMA } = require('./adapter'); | ||
@@ -317,1 +317,33 @@ | ||
}); | ||
test('callCumulusMessageAdapter throws a readable error on schema failure', async(t) => { | ||
const callCumulusMessageAdapter = cumulusMessageAdapter.__get__('callCumulusMessageAdapter'); | ||
const result = await t.throwsAsync(() => callCumulusMessageAdapter('loadNestedEvent', { | ||
event: testContext.inputEvent, | ||
schemas: { input: './test/fixtures/schemas/error_schema/input.json' }, | ||
context: {} | ||
})); | ||
t.regex(result.message, new RegExp('Failed validating u?\'required\' in schema')); | ||
}); | ||
test('generateCMASpawnArguments uses packaged python if no system python', async(t) => { | ||
const messageAdapterDir = process.env.CUMULUS_MESSAGE_ADAPTER_DIR || './cumulus-message-adapter' | ||
const generateCMASpawnArguments = cumulusMessageAdapter.__get__('generateCMASpawnArguments'); | ||
const revert = cumulusMessageAdapter.__set__('lookpath', () => false); | ||
const command = 'foobar'; | ||
const result = await generateCMASpawnArguments(command); | ||
revert(); | ||
t.is(result[0], `${messageAdapterDir}/cma`); | ||
t.deepEqual(result[1], [command]); | ||
}); | ||
test('generateCMASpawnArguments uses system python', async(t) => { | ||
const messageAdapterDir = process.env.CUMULUS_MESSAGE_ADAPTER_DIR || './cumulus-message-adapter' | ||
const generateCMASpawnArguments = cumulusMessageAdapter.__get__('generateCMASpawnArguments'); | ||
const revert = cumulusMessageAdapter.__set__('lookpath', () => '/foo/bar/python'); | ||
const command = 'foobar'; | ||
const result = await generateCMASpawnArguments(command); | ||
revert(); | ||
t.is(result[0], '/foo/bar/python'); | ||
t.deepEqual(result[1], [messageAdapterDir, command]); | ||
}); |
Sorry, the diff of this file is not supported yet
71413
4.01%26
4%1325
5.66%20
11.11%+ Added
- Removed
- Removed
Updated