function getLastRow(sheet) {
  var output = { state: "init", debug: {sheet}, error: "" };
  try {
    var last_row = -1;
    var row_scan = 99999;

    for (let i = 1; i < row_scan; i++) {
      if (checkLastRow(sheet, i)) {
        // print last row number
        last_row = i - 1;
        output = { ...output, debug: { ...output.debug, last_row } };
        console.log("last row is " + last_row.toString());
        break;
      } else {
        // keep going
      }
    }
    if (last_row == -1) {
      throw new Error('cannot find the last row')
    }
    return last_row;
  } catch (error) {
    console.log('getLastRow error')
    output = { ...output, error };
    console.log(output);
  }
}
