Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for difference between stdout/stderr streams #22

Merged
merged 3 commits into from
Jan 19, 2023

Conversation

stillya
Copy link
Contributor

@stillya stillya commented Oct 11, 2022

In current behaviour we have this check l.stderr != l.stdout. By default, stderr and stdout is syscall.Stderr and syscall.Stdout which refer to different fd but actually refer to the same file(By default, they're probably connected to your terminal device), so this check have no sense in this context and by this reason we have two same log(attached screenshot) what wasn't intentable I think.
I added check for difference between stdout and stderr to fix this behaviour.
image

@stillya stillya marked this pull request as draft November 23, 2022 08:29
@stillya stillya marked this pull request as ready for review November 23, 2022 08:29
Copy link
Member

@umputun umputun left a comment

Choose a reason for hiding this comment

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

It appears that the current code may not be accurate, but it is a cost-effective solution. Performing all of the suggested actions on every logf call may be excessive. Could we consider moving the detection to the constructor and setting a field instead? This would be more efficient and still achieve the desired result.

@stillya
Copy link
Contributor Author

stillya commented Jan 18, 2023

Done. Just didn't want to introduce new state.

@stillya stillya requested a review from umputun January 18, 2023 07:10
logger.go Outdated
if outOk && errOk {
outStat, _ := outFile.Stat()
errStat, _ := errFile.Stat()
res.sameStream = os.SameFile(outStat, errStat)
Copy link
Member

@umputun umputun Jan 18, 2023

Choose a reason for hiding this comment

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

omitting an error check bothers me here. I'm not sure in what situation Stat would fail (maybe a permission error or smth like this), but Stat returns an error, and I think it is better to check

Maybe it is also worth extracting the code to some isStreamsSame function, as it's getting too big

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What we gonna do if Stat fail? I think to throw panic, but not sure.

Copy link
Member

Choose a reason for hiding this comment

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

panics from the library is not a good idea. just returns safe default, i.e. false

Copy link
Contributor Author

@stillya stillya Jan 18, 2023

Choose a reason for hiding this comment

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

fixed. Added error handling, extract to function and make some tests. Because I added new import, number of lines changed and some tests failed, so I had to change them

Copy link
Member

@umputun umputun left a comment

Choose a reason for hiding this comment

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

in addition to the comment about err check it would be also nice to have a test for this change

add error handling of os.Stat() with return safe default(false)
add tests for isStreamSame
@stillya stillya requested a review from umputun January 18, 2023 08:11
@umputun
Copy link
Member

umputun commented Jan 19, 2023

It failed tests as action has an old version of go. I'll fix it

@umputun umputun merged commit 1d72ca5 into go-pkgz:master Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants