thegenemyers / DAZZ_DB

The Dazzler Data Base
Other
35 stars 33 forks source link

infinite loop #23

Closed pb-cdunn closed 8 years ago

pb-cdunn commented 8 years ago
touch foo
fasta2DB -v raw_reads -ibar < foo
Skipping 'bar', file is empty!
Skipping 'bar', file is empty!
Skipping 'bar', file is empty!

Use-case:

set -o pipefail
set -o errexit
gunzip -c foo | fasta2DB -v raw_reads -ibar

gzip: foo: not in gzip format

In other words, when the input is accidentally not zipped, that program never ends, so our whole assembly pipeline hangs.

pb-cdunn commented 8 years ago

In our fork, I've fixed this by calling a fatal empty input file an error:

$ git diff
diff --git fasta2DB.c fasta2DB.c
index b080fb5..77ad132 100644
--- fasta2DB.c
+++ fasta2DB.c
@@ -395,10 +395,10 @@ int main(int argc, char *argv[])
         nline = 1;
         eof   = (fgets(read,MAX_NAME,input) == NULL);
         if (eof || strlen(read) < 1)
-          { fprintf(stderr,"Skipping '%s', file is empty!\n",core);
+          { fprintf(stderr,"'%s', file is empty!\n",core);
             fclose(input);
             free(core);
-            continue;
+            goto error;
           }

Gene, look at the markdown for this comment by clicking on the "pencil icon". It looks like this:

    ```diff
    $ git diff
    diff --git fasta2DB.c fasta2DB.c
    ...

The word "diff" after the triple backticks tells GitHub the language to format. I thought you might be pleased to see that it supports your own "diff" output as a format. :smile:

thegenemyers commented 8 years ago

Rather than change behavior, which was to simply skip empty files, I just test if the input is stdin and if so exit the loop. This way it doesn't loop, you just get an empty database.

pb-cdunn commented 8 years ago

Excellent. Thank you.