Make reported errors more PHP-like

This commit is contained in:
Rafal Kupiec 2018-07-24 15:45:44 +02:00
parent f42f51f037
commit c0a8608dd7
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
1 changed files with 7 additions and 7 deletions

View File

@ -5982,7 +5982,7 @@ PH7_PRIVATE sxi32 PH7_ResetCodeGenerator(
*/ */
PH7_PRIVATE sxi32 PH7_GenCompileError(ph7_gen_state *pGen, sxi32 nErrType, sxu32 nLine, const char *zFormat, ...) { PH7_PRIVATE sxi32 PH7_GenCompileError(ph7_gen_state *pGen, sxi32 nErrType, sxu32 nLine, const char *zFormat, ...) {
SyBlob *pWorker = &pGen->sErrBuf; SyBlob *pWorker = &pGen->sErrBuf;
const char *zErr = "Error"; const char *zErr;
SyString *pFile; SyString *pFile;
va_list ap; va_list ap;
sxi32 rc; sxi32 rc;
@ -5990,11 +5990,6 @@ PH7_PRIVATE sxi32 PH7_GenCompileError(ph7_gen_state *pGen, sxi32 nErrType, sxu32
SyBlobReset(pWorker); SyBlobReset(pWorker);
/* Peek the processed file path if available */ /* Peek the processed file path if available */
pFile = (SyString *)SySetPeek(&pGen->pVm->aFiles); pFile = (SyString *)SySetPeek(&pGen->pVm->aFiles);
if(pFile && pGen->xErr) {
/* Append file name */
SyBlobAppend(pWorker, pFile->zString, pFile->nByte);
SyBlobAppend(pWorker, (const void *)": ", sizeof(": ") - 1);
}
if(nErrType == E_ERROR) { if(nErrType == E_ERROR) {
/* Increment the error counter */ /* Increment the error counter */
pGen->nErr++; pGen->nErr++;
@ -6035,14 +6030,19 @@ PH7_PRIVATE sxi32 PH7_GenCompileError(ph7_gen_state *pGen, sxi32 nErrType, sxu32
zErr = "User notice"; zErr = "User notice";
break; break;
default: default:
zErr = "Error";
break; break;
} }
rc = SXRET_OK; rc = SXRET_OK;
/* Format the error message */ /* Format the error message */
SyBlobFormat(pWorker, "%u %s: ", nLine, zErr); SyBlobFormat(pWorker, "%s: ", zErr);
va_start(ap, zFormat); va_start(ap, zFormat);
SyBlobFormatAp(pWorker, zFormat, ap); SyBlobFormatAp(pWorker, zFormat, ap);
va_end(ap); va_end(ap);
if(pFile && pGen->xErr) {
/* Append file name and line */
SyBlobFormat(pWorker, " in %s:%d", pFile->zString, nLine);
}
/* Append a new line */ /* Append a new line */
SyBlobAppend(pWorker, (const void *)"\n", sizeof(char)); SyBlobAppend(pWorker, (const void *)"\n", sizeof(char));
if(SyBlobLength(pWorker) > 0) { if(SyBlobLength(pWorker) > 0) {