Skip to content

Fix #11937: Always print error message to terminal when integration package is not found#11959

Merged
christian-bromann merged 2 commits intowebdriverio:mainfrom
tech-dm-klymenko:dmklymenko-integration-package-absence-print_error
Jan 12, 2024
Merged

Fix #11937: Always print error message to terminal when integration package is not found#11959
christian-bromann merged 2 commits intowebdriverio:mainfrom
tech-dm-klymenko:dmklymenko-integration-package-absence-print_error

Conversation

@tech-dm-klymenko
Copy link
Copy Markdown
Contributor

@tech-dm-klymenko tech-dm-klymenko commented Jan 4, 2024

Fix for #11937

Proposed changes

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Further comments

Reviewers: @webdriverio/project-committers

Comment on lines +115 to +119
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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to do the same thing logFile.write(logText) or am I missing something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 called

In 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 terminal

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the if statement then? Am I missing something?

Copy link
Copy Markdown
Contributor Author

@tech-dm-klymenko tech-dm-klymenko Jan 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 expressions logFile.write(logText) will not be called at all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@christian-bromann christian-bromann added the PR: Bug Fix 🐛 PRs that contain bug fixes label Jan 5, 2024
Copy link
Copy Markdown
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@christian-bromann christian-bromann merged commit 8fe2d8c into webdriverio:main Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Bug Fix 🐛 PRs that contain bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants