for (let i = 0; i < tags.length; i++) {
    const tag = tags?.[i];
    if (!tag) {
      throw new Error("tag is undefined");
    }