[Tex/LaTex] Error: 1 is an integer literal, not a string, for entry

bibtex

I am using the natbib package and a custom .bst file. I am not very familiar with LaTeX unfortunately. The document is able to compile and produce a PDF, but I dont know what the error means. I am using MiKTeX and TeXstudio. This is my .bib entry:

@book{fysikbog,
title = {Physics for Scientists and Engineers, 7th edition},
author = {John W. Jewett and Raymond A. Serway},
year = {2008},
number = {ISBN: 0-495-11240-2},
series = {Paperback},
publisher = {Thomson Learning}
}

This is my .bst file:

https://gist.github.com/rmagni/86813d2eb62ccf6d36e497ac21d425e2

MWE:

\documentclass[a4paper,11pt,fleqn,dvipsnames,twoside,openright]{memoir} 

\usepackage[english]{varioref}              
\usepackage{natbib} 

\bibpunct[,]{[}{]}{;}{a}{,}{,}              
\bibliographystyle{Harvard}         

\begin{document}

This is a citation. \citep{fysikbog}.

\begingroup
\raggedright
\bibliography{litteratur}                           
\endgroup

\end{document}

Thrown Error:

1 is an integer literal, not a string, for entry fysikbog
while executing---line 1485 of file Harvard.bst
(There was 1 error message)

Not sure what the relevant part of this is, but this is the part around line 1485 which the error message mentions:

EXECUTE {begin.bib}

EXECUTE {init.state.consts}

ITERATE {call.type$}

FUNCTION {end.bib}
{ newline$
  "\end{thebibliography}" write$ newline$
}

EXECUTE {end.bib}

Hopefully someone knows what this error means, thanks!

Best Answer

The .bst file has a faulty function definition (ll. 464-472)

FUNCTION {format.year}
{ year duplicate$ empty$
    { "empty year in " cite$ * warning$
       pop$ "" }
    'skip$
  if$
  month empty$
    extra.label *
}

The month empty$ is hanging around there for no reason and causes a 1 to appear on the stack that is then not expected by the rest of the file and causes problems.

I assume the intended definition is closer to

FUNCTION {format.year}
{ year duplicate$ empty$
    { "empty year in " cite$ * warning$
       pop$ "" }
    'skip$
  if$
  extra.label *
}

Furthermore or all calls to format.year should be made as format.year output and not format.year output.check. output.check expects another argument that is not present in the incorrect calls. Simply replace all occurrences of format.year output.check with format.year output.

I have uploaded a corrected version, harvard-fixed.bst, that should work to https://gist.github.com/moewew/170dd99835c17667456738937a5d59d6. You can see the necessary changes in the revision history.