Error when I click on a button with onclick edited by script

I wanted to auto-generate my buttons for selecting a tile type
So I came up with this

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ButtonMenuScript : MonoBehaviour
{
    public static ButtonMenuScript Instance { get; protected set; }

    public GameObject terraformMenu;
    bool terraformMenuEnabled = false;
    public GameObject objectMenu;
    bool objectMenuEnabled = false;
    public GameObject buttonPrefab;

    public void Start()
    {
        if (Instance != null)
        {
            Debug.LogError("Why are there more than one ButtonMenuScript instances?");
        }
        Instance = this;

        terraformMenuEnabled = terraformMenu.activeSelf;
        objectMenuEnabled = objectMenu.activeSelf;
    }

    public void GenerateButton(string menu, string visibleName, string name)
    {
        if(menu == "terraform")
        {
            GameObject button = Instantiate(buttonPrefab);
            button.transform.SetParent(terraformMenu.transform);
            button.name = "Button - " + visibleName;
            button.GetComponentInChildren<Text>().text = visibleName;
            button.GetComponent<Button>().onClick.AddListener(() => { SetTerraform(name); });
        }
    }

    public void SetTerraform(string s)
    {
        MouseController.Instance.SetTerraformTile(s);
    }

    public void terraformMenuEnable()
    {
        terraformMenuEnabled = !terraformMenuEnabled;
        terraformMenu.SetActive(terraformMenuEnabled);
    }
    public void objectMenuEnable()
    {
        objectMenuEnabled = !objectMenuEnabled;
        objectMenu.SetActive(objectMenuEnabled);
    }


}

Everything works fine, the buttons get generated and rendered properly but when I click on any one of them I get this error:

nvm I accidentaly set an empty onclick in the inspector of the prefab