Common Errors includes this annotated image of an error message:

You have the -file-line-error option on so you've also got filename:linenum at the start of the message, which is more useful.
The line containing the error is staggered at the point where TeX has stopped to complain. As Heiko mentioned in the comments, that provides something you can grep for in your source files (including any packages or classes that you've loaded).
There are a number of reasons for an error occurring in the .aux file:
- The build process was interrupted, corrupting the file.
- The
.aux file was accidentally modified while viewing it in an editor (unlikely, but could happen).
- A command has been written to the
.aux file that doesn't get defined until after the .aux file is read in at the start of the document.
- A command that writes information to the
.aux file has an error in the code that's being written to the file, but not executed at that point in the document.
Anything in the .aux file that includes {toc}{\contentsline is typically produced through \addcontentsline, which is defined as:
\addtocontents {#1}{\protect \contentsline {#2}{#3}{\thepage }}
and \addtocontents is defined as:
\protected@write\@auxout{%
\let\label\@gobble
\let\index\@gobble
\let\glossary\@gobble}%
{\string\@writefile{#1}{#2}}
The fact that your error message is in the form
\@writfle
{toc}{\contentsline {chapter}
suggests that \lab isn't using \addcontentsline (or \addtocontents) but explicitly uses \protected@write\@auxout or something has badly messed the definition of \addtocontents or something has corrupted the .aux file after it's been created.
A quick test is to show the definition of \lab just before its problematic usage (remove the .aux file first):
\show\lab
\lab{SD Card}
This will act like an error message, but the transcript will show the definition of that command. (More info on \show.) Does it use \addcontentsline? If so, add \show\addtocontents to check if its usual definition has changed.
If previous instances of \lab have worked fine, then it's possible something has gone wrong between this instance and the last, so try building up or hacking down the bit between the previous \lab and this one.
.logfile, because some IDE's might mingle up the error message in the GUI. If it is\@writfle, then probably the intended correct macro name is\@writefile. Thengrepor similar tools can be used to find the source file location of the misspelled\@writfle. – Heiko Oberdiek May 11 '16 at 04:53max_print_lineto a very high value (100000 or whatever), to turn off line wrapping (see this) (2) understand the error message conventions, e.g. the fact that output is printed in 2 (or 3) of lines, with one line containing everything that has been read so far, and the next line containing the rest, (3) Make sure options like-file-line-errorare set (4) Increase\errorcontextlinesto get full context, (5) learn to look at the.logfile, (6) the answers below … – ShreevatsaR Nov 14 '20 at 00:06