tests: reformat error messages to avoid tripping MSBuild

Change the format of error messages sent to stderr from tests and test
servers. As a workaround to avoid triggering Visual Studio's MSBuild
tool's built-in regexp matcher, and making it mark builds failed for
reasons we don't want them to hard fail.

Roughly, the pattern to avoid is the word "error" (case-insensitive)
in the same line with a colon `:`.

It affected GHA/windows MSVC CI jobs, causing flakiness:
```
CUSTOMBUILD : fopen() failed with error : 13 Permission denied [D:\a\curl\curl\bld\tests\test-ci.vcxproj]
  Error opening file: log/4/smtp_sockfilt.log
[...]
CUSTOMBUILD : fopen() failed with error : 13 Permission denied [D:\a\curl\curl\bld\tests\test-ci.vcxproj]
  Error opening file: log/8/imap_sockfilt.log
  Msg not logged: 00:18:10.656000 > 178 bytes data, server => client
[...]
  TESTDONE: 1629 tests out of 1634 reported OK: 99%
  Building Custom Rule D:/a/curl/curl/tests/CMakeLists.txt
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5): error MSB8066: Custom build for 'D:\a\curl\curl\bld\CMakeFiles\621f80ddbb0fa48179f056ca77842ff0\test-ci.rule;D:\a\curl\curl\tests\CMakeLists.txt' exited with code -1. [D:\a\curl\curl\bld\tests\test-ci.vcxproj]
Error: Process completed with exit code 1.
```
Ref: https://github.com/curl/curl/actions/runs/13643149623/job/38137076210?pr=16490#step:14:3125
Ref: https://github.com/curl/curl/actions/runs/13688765792/job/38277961720?pr=16582#step:14:1717

The `IgnoreStandardErrorWarningFormat="true"` MSBuild Exec option
controls this behavior:
https://learn.microsoft.com/visualstudio/msbuild/exec-task#parameters
I couldn't figure out a way to apply it to CMake builds.

MSBuid pattern matching rules:
353c0f3d37/src/Shared/CanonicalError.cs
https://learn.microsoft.com/visualstudio/msbuild/msbuild-diagnostic-format-for-tasks

Note: There may be further error messages output from runtests scripts,
that use this format, which are not explicitly fatal. They may need
future fixes.

Thanks-to: Dion Williams
Ref: https://github.com/curl/curl/discussions/14854#discussioncomment-12382190
Ref: https://github.com/curl/curl/discussions/14854#discussioncomment-12395224

Closes #16583
This commit is contained in:
Viktor Szakats 2025-03-06 04:13:23 +01:00
parent 8537a5b0bc
commit 9463769f2e
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
14 changed files with 130 additions and 130 deletions

View file

@ -100,7 +100,7 @@ void logmsg(const char *msg, ...)
static int known_offset;
if(!serverlogfile) {
fprintf(stderr, "Error: serverlogfile not set\n");
fprintf(stderr, "Serverlogfile not set error\n");
return;
}
@ -130,9 +130,9 @@ void logmsg(const char *msg, ...)
}
else {
int error = errno;
fprintf(stderr, "fopen() failed with error: %d %s\n",
fprintf(stderr, "fopen() failed with error (%d) %s\n",
error, strerror(error));
fprintf(stderr, "Error opening file: %s\n", serverlogfile);
fprintf(stderr, "Error opening file '%s'\n", serverlogfile);
fprintf(stderr, "Msg not logged: %s %s\n", timebuf, buffer);
}
}
@ -345,14 +345,14 @@ void set_advisor_read_lock(const char *filename)
lockfile = fopen(filename, "wb");
} while(!lockfile && ((error = errno) == EINTR));
if(!lockfile) {
logmsg("Error creating lock file %s error: %d %s",
logmsg("Error creating lock file %s error (%d) %s",
filename, error, strerror(error));
return;
}
res = fclose(lockfile);
if(res)
logmsg("Error closing lock file %s error: %d %s",
logmsg("Error closing lock file %s error (%d) %s",
filename, errno, strerror(errno));
}
@ -371,7 +371,7 @@ void clear_advisor_read_lock(const char *filename)
res = unlink(filename);
} while(res && ((error = errno) == EINTR));
if(res)
logmsg("Error removing lock file %s error: %d %s",
logmsg("Error removing lock file %s error (%d) %s",
filename, error, strerror(error));
}
@ -525,7 +525,7 @@ HANDLE exit_event = NULL;
static void exit_signal_handler(int signum)
{
int old_errno = errno;
logmsg("exit_signal_handler: %d", signum);
logmsg("exit_signal_handler (%d)", signum);
if(got_exit_signal == 0) {
got_exit_signal = 1;
exit_signal = signum;
@ -844,7 +844,7 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
/* socket already exists. Perhaps it is stale? */
curl_socket_t unixfd = socket(AF_UNIX, SOCK_STREAM, 0);
if(CURL_SOCKET_BAD == unixfd) {
logmsg("Failed to create socket at %s: (%d) %s",
logmsg("Failed to create socket at %s (%d) %s",
unix_socket, SOCKERRNO, sstrerror(SOCKERRNO));
return -1;
}
@ -853,7 +853,7 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
error = SOCKERRNO;
sclose(unixfd);
if(0 != rc && ECONNREFUSED != error) {
logmsg("Failed to connect to %s: (%d) %s",
logmsg("Failed to connect to %s (%d) %s",
unix_socket, error, sstrerror(error));
return rc;
}
@ -865,7 +865,7 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
rc = lstat(unix_socket, &statbuf);
#endif
if(0 != rc) {
logmsg("Error binding socket, failed to stat %s: (%d) %s",
logmsg("Error binding socket, failed to stat %s (%d) %s",
unix_socket, errno, strerror(errno));
return rc;
}
@ -878,7 +878,7 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
/* dead socket, cleanup and retry bind */
rc = unlink(unix_socket);
if(0 != rc) {
logmsg("Error binding socket, failed to unlink %s: (%d) %s",
logmsg("Error binding socket, failed to unlink %s (%d) %s",
unix_socket, errno, strerror(errno));
return rc;
}