[Tex/LaTex] bibtex problem with year vs date in book entry

bibtex

So I need to use a custom bibtex style for my thesis, and I have a bibtex entry like

@book{Grupen,
    author={Grupen, Claus},
    title={{Big Bang Nucleosynthesis}},
    publisher={Astroparticle Physics, Springer},
    date={2005},
}

which will compile, but gives a warning

Warning--empty year in Grupen

and, logically, does not display a year in the citation for this entry. If I try to change the entry to

@book{Grupen,
    author={Grupen, Claus},
    title={{Big Bang Nucleosynthesis}},
    publisher={Astroparticle Physics, Springer},
    year={2005},
}

substituting date with year, then I get an error:

You can't pop an empty literal stack for entry Grupen
while executing---line 2529 of file mitthesis.bst 

But mitthesis.bst is only ~1200 lines long, so I am totally baffled about where the problem is. The entry for book looks like this:

FUNCTION {book}
{ output.bibitem
  author empty$
    { format.editors "author and editor" output.check
      add.blank
    }
    { format.authors output.nonnull
      crossref missing$
        { "author and editor" editor either.or.check }
        'skip$
      if$
    }
  if$
  format.btitle "title" output.check
  crossref missing$
    { format.bvolume output
      format.number.series output
      format.publisher.address output
    }
    {
      format.book.crossref output.nonnull
      format.date "year" output.check   
    }
  if$
  format.edition output
  format.note output
  fin.entry
}

Thanks in advance!
———- Edit to add minimum test case:

main.bib:

@book{Grupen,
    author={Grupen, Claus},
    title={{Big Bang Nucleosynthesis}},
    publisher={Astroparticle Physics, Springer},
    year={2005}
}

test.tex

\documentclass[12pt, twoside, singlespace]{article}                 

\begin{document}
asdf\cite{Grupen}

\bibliographystyle{mitthesis}
\bibliography{main}

\cleardoublepage
\thispagestyle{empty}
\mbox{}

\end{document}  

and mitthesis.bst is too big to paste here, but it is here

Best Answer

I am going to mark this as a duplicate because it is the same error that Johannes_B refers to in the comments above. To make the fix clearer I'll also post the answer below:

In mitthesis.bst you need to replace the function format.org.or.pub with the following:

FUNCTION {format.org.or.pub}
{ 't :=
  ""
  year empty$
    { "empty year in " cite$ * warning$ }
    'skip$
  if$
  address empty$ t empty$ and
  year empty$ and
    'skip$
    {
      add.blank "(" *
      t empty$
        { address "address" bibinfo.check *
        }
        { t *
          address empty$
            'skip$
            { ", " * address "address" bibinfo.check * }
          if$
        }
      if$
      year empty$
        'skip$
        { t empty$ address empty$ and
            'skip$
            { 
              ", " *                 %% originally: ", " swap$ * *
            }
          if$
          year "year" bibinfo.check
          *
        }
      if$
      ")" *
    }
  if$