Q:

Treat a 'multiply-defined label' warning as error

Is there a way to treat specific warnings as errors in LaTeX? In particular, is it possible to treat the warning LaTeX Warning: There were multiply-defined labels. as an error?
(I'm guessing a MWE is unnecessary, but here's one for completeness.)
\documentclass{article}

\begin{document}
Hello, world!\label{A}

Bye.\label{A}
\end{document}

I know I can read the log file with any old scripting language and create an error that way, but I'd prefer an immediate response to this error.
(I'm unaware of any drawbacks on treating this specific warning as an error, but would appreciate being told if I'm wrong!)

A:

Not sure how useful this can be; anyway…
\documentclass{article}

\usepackage{xpatch}

\makeatletter
\xpatchcmd{\@newl@bel}
 {\@latex@warning@no@line}
 {\@latex@error}% change warning into error
 {}{}
\xpatchcmd{\@newl@bel}
 {\@latex@warning@no@line}
 {{}\@latex@warning@no@line}% add the required argument to \@latex@error
 {}{}
\makeatother

\begin{document}
Hello, world!\label{A}

Bye.\label{A}
\end{document}

At the second run, LaTeX will stop with
! LaTeX Error: There were multiply-defined labels.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.20 \end{document}

