Skip to content

Conversation

@ttaylorr
Copy link
Contributor

This pull request addresses the second and third points of #2076:

(2) On Windows, checking this logfile with an application that does not support Linux-style line endings results in this, which is unusual even for cross-platform systems:

This one required some investigation. I originally thought that the goal here was to replace all instances of printing LF (\n) characters sent to the terminal, but the actual fix is to just print platform-specific line ending sequences to files on disk, not the terminal.

To determine this, I wrote two files to my ~/github/share directory, which is accessible via my Windows VM. Each had the words "foo" and "bar". One was separated by a LF character, and the other by a CRLF, as follows:

~/g/git-lfs (x-platform-logs-formatting) $ echo -n "foo\nbar" > ~/github/share/example_lf
~/g/git-lfs (x-platform-logs-formatting) $ hexdump -C < ~/github/share/example_lf
00000000  66 6f 6f 0a 62 61 72                              |foo.bar|
00000007
~/g/git-lfs (x-platform-logs-formatting) $ echo -n "foo\r\nbar" > ~/github/share/example_crlf
~/g/git-lfs (x-platform-logs-formatting) $ hexdump -C < ~/github/share/example_crlf
00000000  66 6f 6f 0d 0a 62 61 72                           |foo..bar|
00000008

On Windows, they render in the terminal as expected independent of the line ending sequences (tested via cmd.exe, and reproducible in Git Bash):

C:\Users\ttaylorr>type "\\vmware-host\Shared Folders\share\example_crlf"
foo
bar
C:\Users\ttaylorr>type "\\vmware-host\Shared Folders\share\example_lf"
foo
bar

So the fix in 43ec8e9 involved:

  • Adding a lineEnding argument to the logPanicToWriter() func. This function is used to print to both os.Stderr, as well as *os.File instances, so it needs to be able to handle either LF or CRLFs.
  • Picking the right line ending sequence for each. For this, we can lean on the existing gitLineEnding func, which prefers your core.autocrlf setting, or defaults to the platform correct sequence instead.

(3) After converting the line endings, the relevant error message is way out on the right side of the screen, which significantly hinders reading comprehension for a user trying to parse these for the first time.

This is a larger problem with my (perhaps) excessive use of error-wrapping, but is easily solved by formatting errors with %+v instead of %s. Here's a before and after:

  • With %s (old):
e3: e2: e1
<stacktrace>
  • With %+v (new):
e1
<snip>
github.com/git-lfs/git-lfs/errors.newWrappedError
        /Users/ttaylorr/go/src/github.com/git-lfs/git-lfs/errors/types.go:166: e2
github.com/git-lfs/git-lfs/errors.newWrappedError
        /Users/ttaylorr/go/src/github.com/git-lfs/git-lfs/errors/types.go:166: e3

Closes: #2076.


/cc @git-lfs/core @JarrettR #2076

@ttaylorr ttaylorr added this to the v2.1.0 milestone Apr 25, 2017
@ttaylorr ttaylorr requested a review from technoweenie April 25, 2017 19:14
Copy link
Contributor

@technoweenie technoweenie left a comment

Choose a reason for hiding this comment

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

Looks good. Great description of the fix :)

@ttaylorr ttaylorr merged commit 50184ea into master Apr 25, 2017
@ttaylorr ttaylorr deleted the x-platform-logs-formatting branch April 25, 2017 19:51
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Feb 28, 2025
In PR git-lfs#1466 we introduced our custom "errors" package as a replacement
for the "errutil" package used previously to provide various error
handling functions and specialized error types.  As part of this PR,
in commit 8624a87 we defined the
StackTrace() function in the new "errors" package, and updated the
logPanicToWriter() function in our "commands" package to call it
when generating an error log file.  We write these log files to
the .git/lfs/logs directory whenever a Git LFS command invokes one
of our error reporting utility functions such as LoggedError() or
Panic().

Later, in commit 377366d of PR git-lfs#2178,
we revised the logPanicToWriter() function to use the "%+v" format
string specifier when writing an error's details to the log file,
and dropped the call to the StackTrace() function of our "errors"
package.

The StackTrace() call was deemed no longer necessary because we
expect all of our errors to be created using our "errors" package's
functions, which instantiate error structures defined by the legacy
"github.com/pkg/errors" package.  This package defines its own
Format() methods for its structures so that when the "%+v" format
string specifier is used with them, they output both the message
and stack trace associated with each error.

As a consequence of this change in PR git-lfs#2178, the StackTrace()
function in our own custom "errors" package has no remaining callers,
so we can remove it now.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Mar 5, 2025
In PR git-lfs#1466 we introduced our custom "errors" package as a replacement
for the "errutil" package used previously to provide various error
handling functions and specialized error types.  As part of this PR,
in commit 8624a87 we defined the
StackTrace() function in the new "errors" package, and updated the
logPanicToWriter() function in our "commands" package to call it
when generating an error log file.  We write these log files to
the .git/lfs/logs directory whenever a Git LFS command invokes one
of our error reporting utility functions such as LoggedError() or
Panic().

Later, in commit 377366d of PR git-lfs#2178,
we revised the logPanicToWriter() function to use the "%+v" format
string specifier when writing an error's details to the log file,
and dropped the call to the StackTrace() function of our "errors"
package.

The StackTrace() call was deemed no longer necessary because we
expect all of our errors to be created using our "errors" package's
functions, which instantiate error structures defined by the legacy
"github.com/pkg/errors" package.  This package defines its own
Format() methods for its structures so that when the "%+v" format
string specifier is used with them, they output both the message
and stack trace associated with each error.

As a consequence of this change in PR git-lfs#2178, the StackTrace()
function in our own custom "errors" package has no remaining callers,
so we can remove it now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error reporting

3 participants