Skip to content

Commit

Permalink
Merge pull request #6 from snyk/fix/better-error-message
Browse files Browse the repository at this point in the history
Fix/better error message
  • Loading branch information
deebugger authored Sep 17, 2017
2 parents ca03bf6 + a4cef1c commit cc09bad
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 15 deletions.
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ function inspect(root, targetFile, options) {
try {
parseResult = parse(result, options.dev);
} catch (error) {
console.log('\n', error, '\n');
return Promise.reject(
'An internal error has occured. Please contact Snyk for support.');
console.log('\nAn unknown error occurred. ' +
'Please include the trace below when reporting to Snyk:', error, '\n');
return Promise.reject('');
}
if (parseResult.ok) {
return {
Expand Down
26 changes: 14 additions & 12 deletions lib/parse-mvn.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@ var digraph = /digraph([\s\S]*?)\}/g;

// Parse the output from 'mvn dependency:tree -DoutputType=dot'
function parseTree(text, withDev) {
// look for '[INFO] digraph' - otherwise return an error
var match = text.match(/(^\[INFO\] digraph)/m);
if (!match) {
text = text.replace(logLabel, '');
try {
return {
ok: true,
data: getRootProject(text, withDev),
};
} catch (error) {
return {
ok: false,
message: 'Error: Cannot find dependency information. ' +
'Please make sure that Apache Maven Dependency Plugin ' +
'version 2.2 or above is installed.',
message: error.message,
error: error,
};
}

text = text.replace(logLabel, '');
return {
ok: true,
data: getRootProject(text, withDev),
};
}

function getRootProject(text, withDev) {
var projects = text.match(digraph);
if (!projects) {
throw new Error('Error: Cannot find dependency information. ' +
'Please make sure that Apache Maven Dependency Plugin ' +
'version 2.2 or above is installed.');
}
var root = getProject(projects[0], null, withDev);
// Add any subsequent projects to the root as dependencies
for (var i = 1; i < projects.length; i++) {
Expand Down
47 changes: 47 additions & 0 deletions test/fixtures/pom.dep-plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>io.snyk.example</groupId>
<artifactId>test-project</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Test project</name>
<description>Test project for the Maven CLI plugin</description>

<properties>
<axis.version>1.4</axis.version>
</properties>

<dependencies>

<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>${axis.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>

<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</pluginManagement>

</build>

</project>
14 changes: 14 additions & 0 deletions test/system/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ test('run inspect() with --dev', function (t) {
'test deps found');
});
});

test('run inspect() with a bad dependency plugin', function (t) {
t.plan(1);
return plugin.inspect('.', path.join(
__dirname, '..', 'fixtures', 'pom.dep-plugin.xml'), {dev: true})
.then(function (result) {
t.fail('bad dependency plugin - we should not be here');
})
.catch(function (error) {
t.equal(error, 'Error: Cannot find dependency information. ' +
'Please make sure that Apache Maven Dependency Plugin ' +
'version 2.2 or above is installed.', 'correct failure message');
});
});

0 comments on commit cc09bad

Please sign in to comment.