Invalid Record Length: expect 3, got 1 on line 2

script creates output csv file
some columns are empty

I am getting error on
csvRead output file

expect 3, got 1 on line 2
number can change depending upon data

use this macro to reproduce the error

{
      "Command": "store",
      "Target": "row 1 - 1",
      "Value": "!csvline",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "row 1 - 2",
      "Value": "!csvline",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "row 1 - 3",
      "Value": "!csvline",
      "Description": ""
    },
    {
      "Command": "csvSave",
      "Target": "output",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "row 2 - 1",
      "Value": "!csvline",
      "Description": ""
    },
    {
      "Command": "csvSave",
      "Target": "output",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "csvRead",
      "Target": "output",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${!col1}",
      "Value": "red",
      "Description": ""
    }

Screenshot 2024-06-17 132723

The number of cells must be the same in each row. In your macro row1 has 3 cells (columns), but row2 has only one cell. This triggers the error.

This macro works:

{
  "Name": "csv1",
  "CreationDate": "2024-6-17",
  "Commands": [
    {
      "Command": "store",
      "Target": "row 1 - 1",
      "Value": "!csvline",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "row 1 - 2",
      "Value": "!csvline",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "row 1 - 3",
      "Value": "!csvline",
      "Description": ""
    },
    {
      "Command": "csvSave",
      "Target": "outputnew",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "row 2 - 1",
      "Value": "!csvline",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "row 2 - 2",
      "Value": "!csvline",
      "Description": "fill 2nd column"
    },
    {
      "Command": "store",
      "Target": "row 2 - 3",
      "Value": "!csvline",
      "Description": "fill 3rd column - this way the number of cells is the same in each row"
    },
    {
      "Command": "csvSave",
      "Target": "outputnew",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "csvRead",
      "Target": "outputnew",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Row1, Col1: ${!col1}",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Total number of rows in file: ${!csvReadMaxRow}",
      "Value": "blue",
      "Description": ""
    }
  ]
}

I know the reason

so this is a requirement for csvRead command that all columns should have data?

because I have to extract data and save to CSV file
then I have to read CSV file

Yes. The first row read by csvRead is analyzed for its numbers of columns (in the above example: 3 columns). The command then expects that all further rows have exactly the same number of columns.