Fix #11937: Always print error message to terminal when integration package is not found#11959
Conversation
| if (!logsContainInitPackageError(logText)) { | ||
| return logFile.write(logText) | ||
| } | ||
| // If we get Error during init of integration packages, write logs to both "outputDir" and the terminal | ||
| logFile.write(logText) |
There was a problem hiding this comment.
This seems to do the same thing logFile.write(logText) or am I missing something?
There was a problem hiding this comment.
Yes, that's correct, the expression logFile.write(logText) is used twice. Here it is necessary to cover different scenarios.
In the first case, when the logs do not contain the target error related to the inability to find the integration package, everything happens as usual - this statement is used return logFile.write(logText), logs are made to the file, and the flow ends with return
Case 1
if (!logsContainInitPackageError(logText)) {
return logFile.write(logText) // << write to file
}
logFile.write(logText) // << this method is not calledIn the second case, when the logs contain the target error, logs are also made to the file, but the flow does not stop at this point; instead, it continues further. Additionally, the error is output to the terminal using statement rawMethod(...args)
Case 2
if (!logsContainInitPackageError(logText)) {
return logFile.write(logText) // << not called
}
logFile.write(logText) // << write error to file when 'outputDir' is specified
}
....
rawMethod(...args) // << also write error to the terminalThere was a problem hiding this comment.
Why do we need the if statement then? Am I missing something?
There was a problem hiding this comment.
In this case, these expressions logFile.write(logText) are within the 'outputDir' block and are not related to terminal output. So this condition if (!logsContainInitPackageError(logText)) allows for the necessary transition and links logging to the directory with its display in the terminal.
Without this condition, we could either write logs only to the terminal or only to a file. This condition allows checking the log text for the presence of an integration package error:
- If there is no integration package error and it is a regular log, then we write only to the file.
- If it is integration package error, then we should not interrupt the flow. Instead, we first write the log to the file (since the user specified
outputDir) and then also to the terminal to enhance the DX. - If the user has not specified
outputDir, then we output all logs to the terminal and these two expressionslogFile.write(logText)will not be called at all.
There was a problem hiding this comment.
Oh, now I see that the logFile.write(logText) outside of the if statement doesn't return and execution continues in line 122 and 123. Sorry for that. Makes totally sense now.
Fix for #11937
Proposed changes
Types of changes
Checklist
Further comments
Reviewers: @webdriverio/project-committers