Skip to content

Commit

Permalink
Fix error reporting on missing script file #1951
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed Dec 22, 2021
1 parent 64bb66d commit e1a0b24
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
27 changes: 27 additions & 0 deletions modules/nextflow/src/main/groovy/nextflow/cli/CmdRun.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,33 @@ class CmdRun extends CmdBase implements HubOptions {
}

protected ScriptFile getScriptFile(String pipelineName) {
try {
getScriptFile0(pipelineName)
}
catch (IllegalArgumentException | AbortOperationException e) {
if( e.message.startsWith("Not a valid project name:") && !guessIsRepo(pipelineName)) {
throw new AbortOperationException("Cannot find script file: $pipelineName")
}
else
throw e
}
}

static protected boolean guessIsRepo(String name) {
if( FileHelper.getUrlProtocol(name) != null )
return true
if( name.startsWith('/') )
return false
if( name.startsWith('./') || name.startsWith('../') )
return false
if( name.endsWith('.nf') )
return false
if( name.count('/') != 1 )
return false
return true
}

protected ScriptFile getScriptFile0(String pipelineName) {
assert pipelineName

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,19 @@ class AssetManager {
String resolveName( String name ) {
assert name

//
// check if it's a repository fully qualified URL e.g. https://github.com/foo/bar
//
def project = resolveNameFromGitUrl(name)
if( project )
return project

//
// otherwise it must be a canonical repository name e.g. user/project
//
if( ['./','../', '/' ].any(it->name.startsWith(it)) )
throw new AbortOperationException("Not a valid project name: $name")

def parts = name.split('/') as List<String>
def last = parts[-1]
if( last.endsWith('.nf') || last.endsWith('.nxf') ) {
Expand Down Expand Up @@ -459,7 +468,7 @@ class AssetManager {
result = (ConfigObject)config.manifest
}
catch( Exception e ) {
throw new Exception("Project config file is malformed -- Cause: ${e.message ?: e}", e)
throw new AbortOperationException("Project config file is malformed -- Cause: ${e.message ?: e}", e)
}

// by default return an empty object
Expand Down
15 changes: 15 additions & 0 deletions modules/nextflow/src/test/groovy/nextflow/cli/CmdRunTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,19 @@ class CmdRunTest extends Specification {
then:
cmd.getDisableJobsCancellation() == true
}

@Unroll
def 'should guss is repo' () {
expect:
CmdRun.guessIsRepo(PATH) == EXPECTED

where:
EXPECTED | PATH
true | 'http://github.com/foo'
true | 'foo/bar'
and:
false | 'script.nf'
false | '/some/path'
false | '../some/path'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ class AssetManagerTest extends Specification {
then:
thrown(AbortOperationException)

when:
result = manager.resolveName('../blast/script.nf')
then:
thrown(AbortOperationException)

when:
result = manager.resolveName('./blast/script.nf')
then:
thrown(AbortOperationException)

}


Expand Down

0 comments on commit e1a0b24

Please sign in to comment.