Skip to content

Commit

Permalink
[validate] Provide invalid BIDS root error
Browse files Browse the repository at this point in the history
Closes #107

Provide the appropriate error when the BIDS validator is not run
from the root BIDS folder structure.
  • Loading branch information
mpsonntag committed Jul 29, 2022
1 parent 3c14ab0 commit 01a7e6b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions internal/web/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func handleValidationConfig(cfgpath string) (Validationcfg, error) {
// and saves the results to the appropriate document for later viewing.
func validateBIDS(valroot, resdir string) error {
srvcfg := config.Read()
// Use validation config file if available
var validateNifti bool

// Use validation config file if available
cfgpath := filepath.Join(valroot, srvcfg.Label.ValidationConfigFile)
log.ShowWrite("[Info] looking for config file at %q", cfgpath)
if fi, err := os.Stat(cfgpath); err == nil && !fi.IsDir() {
Expand Down Expand Up @@ -118,17 +118,19 @@ func validateBIDS(valroot, resdir string) error {
serr.Reset()
cmd.Stdout = &out
cmd.Stderr = &serr
// cmd.Dir = tmpdir
if err := cmd.Run(); err != nil {
return fmt.Errorf("[Error] running bids validation (%s): %q, %q", valroot, err.Error(), serr.String())
err := cmd.Run()
// Only return if the error is not related to the bids validation; if the out string contains information
// we can continue
if err != nil && !strings.Contains(out.String(), "QUICK_VALIDATION_FAILED") {
return fmt.Errorf("[Error] running bids validation (%s): %q, %q, %q", valroot, err.Error(), serr.String(), out.String())
}

// We need this for both the writing of the result and the badge
output := out.Bytes()

// CHECK: can this lead to a race condition, if a job for the same user/repo combination is started twice in short succession?
outFile := filepath.Join(resdir, srvcfg.Label.ResultsFile)
err := ioutil.WriteFile(outFile, []byte(output), os.ModePerm)
err = ioutil.WriteFile(outFile, []byte(output), os.ModePerm)
if err != nil {
return fmt.Errorf("[Error] writing results file for %q", valroot)
}
Expand Down

0 comments on commit 01a7e6b

Please sign in to comment.