From f607cf9107ce8f67930b402759258ef8b8e87f7e Mon Sep 17 00:00:00 2001 From: George Marchment <georgemarchment@yahoo.fr> Date: Wed, 16 Apr 2025 11:50:45 +0200 Subject: [PATCH] Added while upper bound for the while for the extarction of conditions -> gonna do the same for the rest of the whiles --- src/constant.py | 2 ++ src/outils.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/constant.py b/src/constant.py index 400e439..8f32dbe 100644 --- a/src/constant.py +++ b/src/constant.py @@ -2,6 +2,8 @@ # CONSTANT VARIABLES #========================== +WHILE_UPPER_BOUND = 1000000 + ERROR_WORDS = ['null', "params", "log", "workflow", "it", "config"] ERROR_WORDS_ORIGINS = ['channel', 'Channel', 'null', "params", "logs", "workflow", "log", diff --git a/src/outils.py b/src/outils.py index fdc5535..c941f71 100644 --- a/src/outils.py +++ b/src/outils.py @@ -1,6 +1,9 @@ import re import subprocess import os +from .constant import WHILE_UPPER_BOUND +from .bioflowinsighterror import BioFlowInsightError + #============================================================= # THESE A JUST UTILITY FUNCTIONS TO BE ABLE TO MANIPULATE CODE @@ -932,7 +935,8 @@ def extract_conditions(code, only_get_inside = True): triple_single, triple_double = False, False - while(start<len(code)): + timeout = 0 + while(start<len(code) and timeout < WHILE_UPPER_BOUND): checked_triple = False if(start+3<=len(code)): if(code[start:start+3]=="'''" and not quote_single and not quote_double and not triple_single and not triple_double): @@ -1056,6 +1060,9 @@ def extract_conditions(code, only_get_inside = True): start = end-1 start+=1 + timeout+=1 + if(timeout>=WHILE_UPPER_BOUND): + raise BioFlowInsightError("The WHILE_UPPER_BOUND was exceeded. BioFlow-Insight was unable to extarct the conditions. Make sure the workflow uses correct Nextflow syntaxe (https://www.nextflow.io/docs/latest/index.html).", type="Unable to extract conditions") for c in conditions_dico: start, end = conditions_dico[c] return conditions_dico -- GitLab