Browse Source

Reduce transformers error message chain

semi-dynamic-namespace-imports
Bogdan Chadkin 9 years ago
parent
commit
bd1c379a17
  1. 9
      src/utils/transform.js
  2. 25
      test/function/throws-only-first-transform-bundle/_config.js
  3. 1
      test/function/throws-only-first-transform-bundle/main.js
  4. 29
      test/function/throws-only-first-transform/_config.js
  5. 1
      test/function/throws-only-first-transform/main.js

9
src/utils/transform.js

@ -31,9 +31,12 @@ export default function transform ( source, id, plugins ) {
return result.code;
});
}).catch( err => {
err.id = id;
err.plugin = plugin.name;
err.message = `Error transforming ${id}${plugin.name ? ` with '${plugin.name}' plugin` : ''}: ${err.message}`;
if ( !err.rollupTransform ) {
err.rollupTransform = true;
err.id = id;
err.plugin = plugin.name;
err.message = `Error transforming ${id}${plugin.name ? ` with '${plugin.name}' plugin` : ''}: ${err.message}`;
}
throw err;
});
}, Promise.resolve( source.code ) )

25
test/function/throws-only-first-transform-bundle/_config.js

@ -0,0 +1,25 @@
var assert = require( 'assert' );
module.exports = {
description: 'throws error only with first plugin transformBundle',
options: {
plugins: [
{
name: 'plugin1',
transformBundle: function () {
throw Error('Something happend 1');
}
},
{
name: 'plugin2',
transformBundle: function () {
throw Error('Something happend 2');
}
}
]
},
generateError: function ( err ) {
assert.equal( err.plugin, 'plugin1' );
assert.equal( err.message, 'Error transforming bundle with \'plugin1\' plugin: Something happend 1' );
}
};

1
test/function/throws-only-first-transform-bundle/main.js

@ -0,0 +1 @@
console.log(1);

29
test/function/throws-only-first-transform/_config.js

@ -0,0 +1,29 @@
var assert = require( 'assert' );
var path = require( 'path' );
module.exports = {
description: 'throws error only with first plugin transform',
options: {
plugins: [
{
name: 'plugin1',
transform: function () {
throw Error('Something happend 1');
}
},
{
name: 'plugin2',
transform: function () {
throw Error('Something happend 2');
}
}
]
},
error: function ( err ) {
var id = path.resolve( __dirname, 'main.js' );
assert.equal( err.rollupTransform, true );
assert.equal( err.id, id );
assert.equal( err.plugin, 'plugin1' );
assert.equal( err.message, 'Error transforming ' + id + ' with \'plugin1\' plugin: Something happend 1' );
}
};

1
test/function/throws-only-first-transform/main.js

@ -0,0 +1 @@
console.log(1);
Loading…
Cancel
Save