Skip to content

Errutil to errors#1466

Merged
technoweenie merged 12 commits intomasterfrom
errutil-to-errors
Aug 19, 2016
Merged

Errutil to errors#1466
technoweenie merged 12 commits intomasterfrom
errutil-to-errors

Conversation

@technoweenie
Copy link
Contributor

This renames the github/git-lfs/errutil package to github/git-lfs/errors, and encourages its use in the rest of the codebase instead of errors or github.com/pkg/errors.

This is still (mostly) API compatible with both, and means we don't have to import multiple error packages in Git LFS itself.

@@ -0,0 +1,42 @@
package errors

type errorWithContext interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

This name is slightly misleading, since errorWithContext isn't actually an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, the prefix is redundant. I think we should go with withContext, and methods like SetContext() instead of ErrorSetContext().

@ttaylorr
Copy link
Contributor

Aside from my one comment, 👍 .

@technoweenie
Copy link
Contributor Author

Using pkg/errors really reduces the stack trace:

current master

$ git-lfs clone https://ghe.io/technoweenie/lfs-pull-bug
Skipped checkout for a.bin, content not local. Use fetch to download.

File missing and download is not allowed: Error
goroutine 66 [running]:
github.com/github/git-lfs/errutil.Stack(0x3a2a00, 0x5b16a0, 0xc420460dd0)
          /Users/rick/go/src/github.com/github/git-lfs/errutil/errors.go:518 +0x74
github.com/github/git-lfs/commands.logPanicToWriter(0x5b0a20, 0xc42002f010, 0x5b16a0, 0xc420460dd0)
          /Users/rick/go/src/github.com/github/git-lfs/commands/commands.go:272 +0xae7
github.com/github/git-lfs/commands.logPanic(0x5b16a0, 0xc420460dd0, 0x0, 0x0)
          /Users/rick/go/src/github.com/github/git-lfs/commands/commands.go:236 +0x316
github.com/github/git-lfs/commands.handlePanic(0x5b16a0, 0xc420460dd0, 0xc420283ed8, 0x1)
          /Users/rick/go/src/github.com/github/git-lfs/commands/commands.go:211 +0x3a
github.com/github/git-lfs/commands.LoggedError(0x5b16a0, 0xc420460dd0, 0x40cee5, 0x42, 0xc420283ed8, 0x1, 0x1)
          /Users/rick/go/src/github.com/github/git-lfs/commands/commands.go:151 +0x84
github.com/github/git-lfs/commands.checkoutWithChan(0xc420072120)
          /Users/rick/go/src/github.com/github/git-lfs/commands/command_checkout.go:198 +0x6a1
github.com/github/git-lfs/commands.checkoutFromFetchChan.func1(0xc420072120, 0xc420460c70)
          /Users/rick/go/src/github.com/github/git-lfs/commands/command_checkout.go:70 +0x2b
created by github.com/github/git-lfs/commands.checkoutFromFetchChan
          /Users/rick/go/src/github.com/github/git-lfs/commands/command_checkout.go:72 +0x3d5

this pr

$ git-lfs clone https://ghe.io/technoweenie/lfs-pull-bug
Skipped checkout for a.bin, content not local. Use fetch to download.

stat /Users/rick/p/lfs-pull-bug/.git/lfs/objects/f2/ca/f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2: no such file or directory
github.com/github/git-lfs/errors.newWrappedError
        /Users/rick/go/src/github.com/github/git-lfs/errors/types.go:166: smudge

@technoweenie
Copy link
Contributor Author

You can replicate this with:

$ git lfs install --skip-smudge
$ git clone https://github.com/small/repo/with/lfs/objects
$ cd working-dir
$ git lfs checkout

This raises the same error because the .git/lfs/objects dir is empty since skip-smudge is enabled.

@technoweenie
Copy link
Contributor Author

Fixed the problem. Turns out we're on an old version of the pkg/errors package, so I was looking at the wrong code. 8624a87 changes the formatting for the error from %+v to %s. I thought %+v would print the entire stack trace for the error, but it only prints the first frame.

My change adds an errors.StackTrace() function that pulls the frames out, and formats each individual frame with %+v.

I now have a full stacktrace:

$ git-lfs checkout
Skipped checkout for png/render.png, content not local. Use fetch to download.

smudge: stat /Users/rick/p/git-lfs-test/.git/lfs/objects/55/d5/55d51edb307ed7bf4a1bbca3867d132a07f76828d57f37e0f31f712c02ceafe0: no such file or directory
github.com/github/git-lfs/errors.newWrappedError
        /Users/rick/go/src/github.com/github/git-lfs/errors/types.go:166
github.com/github/git-lfs/errors.NewDownloadDeclinedError
        /Users/rick/go/src/github.com/github/git-lfs/errors/types.go:317
github.com/github/git-lfs/lfs.PointerSmudge
        /Users/rick/go/src/github.com/github/git-lfs/lfs/pointer_smudge.go:62
github.com/github/git-lfs/lfs.PointerSmudgeToFile
        /Users/rick/go/src/github.com/github/git-lfs/lfs/pointer_smudge.go:27
github.com/github/git-lfs/commands.checkoutWithChan
        /Users/rick/go/src/github.com/github/git-lfs/commands/command_checkout.go:194
github.com/github/git-lfs/commands.checkoutWithIncludeExclude.func1
        /Users/rick/go/src/github.com/github/git-lfs/commands/command_checkout.go:102
runtime.goexit
        /usr/local/Cellar/go/1.7/libexec/src/runtime/asm_amd64.s:2086

@ttaylorr
Copy link
Contributor

Awesome find, glad that wasn't as involved as I was thinking it would be 😅

@technoweenie technoweenie merged commit ddfaae3 into master Aug 19, 2016
@technoweenie technoweenie deleted the errutil-to-errors branch August 19, 2016 20:13
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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants