Skip to content

Commit

Permalink
Improve err handling for missing files
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed Oct 25, 2023
1 parent 994c502 commit 98df6ea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/src/main/java/io/seqera/wave/cli/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ protected void validateArgs() {
if( !isEmpty(condaFile) && !isEmpty(spackFile) )
throw new IllegalCliArgumentException("Option --conda-file and --spack-file conflict each other");

if( !isEmpty(condaFile) && !Files.exists(Path.of(condaFile)) )
throw new IllegalCliArgumentException("The specified Conda file path cannot be accessed - offending file path: " + condaFile);

if( !isEmpty(spackFile) && !Files.exists(Path.of(spackFile)) )
throw new IllegalCliArgumentException("The specified Spack file path cannot be accessed - offending file path: " + spackFile);

if( !isEmpty(contextDir) && isEmpty(containerFile) )
throw new IllegalCliArgumentException("Option --context requires the use of a container file");

Expand Down
14 changes: 14 additions & 0 deletions app/src/test/groovy/io/seqera/wave/cli/AppCondaOptsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ class AppCondaOptsTest extends Specification {
thrown(IllegalCliArgumentException)
}

def 'should fail when the conda file does not exist' () {
given:
def app = new App()
String[] args = ["--conda-file", "foo"]

when:
new CommandLine(app).parseArgs(args)
and:
app.validateArgs()
then:
def e = thrown(IllegalCliArgumentException)
e.message == "The specified Conda file path cannot be accessed - offending file path: foo"
}

def 'should fail when passing both conda package and image' () {
given:
def app = new App()
Expand Down
16 changes: 15 additions & 1 deletion app/src/test/groovy/io/seqera/wave/cli/AppSpackOptsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AppSpackOptsTest extends Specification {
thrown(IllegalCliArgumentException)
}

def 'should fail when passing both spack file and conmtainer file' () {
def 'should fail when passing both spack file and container file' () {
given:
def app = new App()
String[] args = ["--spack-file", "foo", "--containerfile", "bar"]
Expand All @@ -68,6 +68,20 @@ class AppSpackOptsTest extends Specification {
thrown(IllegalCliArgumentException)
}

def 'should fail when spack file does not exist' () {
given:
def app = new App()
String[] args = ["--spack-file", "foo"]

when:
new CommandLine(app).parseArgs(args)
and:
app.validateArgs()
then:
def e = thrown(IllegalCliArgumentException)
e.message == 'The specified Spack file path cannot be accessed - offending file path: foo'
}

def 'should fail when passing both spack package and image' () {
given:
def app = new App()
Expand Down

0 comments on commit 98df6ea

Please sign in to comment.