This Code always crashes the Workspace - v1.29.1

I have this Code Node that completely crashes the Workspace:

var taxonomies = $('Prepare WP Taxonomies Loop - New').item.json.taxonomies;
var terms_existing = [];
var terms_new = [];

var find_str_in_arr = function (str, arr) {

  for( var i = 0; i < arr.length; i++ ){
    //console.log("arr", i, arr[i]);
    if( (arr[i].name).toLowerCase() == str.toLowerCase() ){
      return arr[i];
    }
  }

  return false;

}

for( var i = 0; i < taxonomies.length; i++ ){

  var taxonomy = taxonomies[i];

  // New Terms generated by AI for Recipe
  var terms_ai = $('Prepare WP Terms - New').all()[0].json[taxonomy];

  // Existing Terms in WP
  var terms_wp = $('Example Data - Existing').all()[0].json[taxonomy].wp_terms;

  // Make sure @terms_ai is Array
  if( Array.isArray(terms_ai) ){
    // Is already an Array, do nothing
  }else if( typeof terms_ai === 'string' || terms_ai instanceof String ){
    // Is a comma separated list
    var terms_ai = terms_ai.split(",");
  }else{
    // Is an integer or float
    var terms_ai = [terms_ai.toString()];
  }

  // Loop all @terms_ai
  for( var i = 0; i < terms_ai.length; i++ ){

	var term = (terms_ai[i]).trim();

    // Make sure is not empty
    if(!term){
      continue;
    }

    // Extract Matching WP Term ID, if we have a @term
    var found_wp_term = find_str_in_arr(term, terms_wp);

    if( found_wp_term === false ){
      //terms_new.push({[taxonomy]: term});
    }else{
      //terms_existing.push({[taxonomy]: found_wp_term.id});
    }

  }

}

return {
  'terms_existing': terms_existing,
  'terms_new': terms_new
};

Can anyone see anything wrong in the code?

My first guess was that the problem is the Computed property names in here:

   if( found_wp_term === false ){
      terms_new.push({[taxonomy]: term});
    }else{
      terms_existing.push({[taxonomy]: found_wp_term.id});
    }

But I comment them out and Workspace crashes, so I really have no idea.

It should throw an error and stop execution, but instead it completely crashes the Workspace. 3 times now and it takes a few minutes to come back. I am a bit desperate because I need to be able to make it run.

I can’t attach an example Workflow because it says I am exceeding the limit.

Running N8N online version 1.29.1

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:
1 Like

Just found the problem.

It is the second loop inside another loop.

It is not the data, is simply by making a loop inside another loop in the Code Node.

Omg I am so desperate because the Loop Nodes also faill when nested.

Please help!

you can share the workflow in a separate post. Without the workflow it’s hard to say what the problem is.

Ok so I kept looking into it and indeed there was an error in the code.

The second for loop was using same parameter name i, as soon as I changed it to something else it is working perfectly.

It was so obvious, just drifted out with the workspace crashing and having to wait so long.

Block me right now! Restrict me from creating new posts! :crazy_face: :crazy_face:

2 Likes

Hey @Cristian_DF,

I can block you if you want :joy:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.