koog1000 / vscode-fossil

Integrated Fossil source control for Visual Studio Code
Other
68 stars 8 forks source link

Repeated errors outside a checkout when system fossil build is newer than 2022-12-21 #107

Closed otherjoel closed 1 year ago

otherjoel commented 1 year ago

I don’t use Fossil for all my projects, only some. This extension throws an error “Fossil: current directory not within an open checkout” when I open, close, or switch files when the folder I have open is not from a Fossil repo.

image

Contents of “Output” tab in bottom panel:

fossil status: 4ms // getting root for '/Users/joel/code/[…]'
current directory is not within an open check-out

fossil status: 6ms // getting root for '/Users/joel/code/[…]'
current directory is not within an open check-out

fossil status: 4ms // getting root for '/Users/joel/code/[…]'
current directory is not within an open check-out

This happens even if I disable the Auto Refresh setting (User or Workspace or both, makes no difference). It happens when the current folder has actually been initialized as a git repo, and it happens when there is no version control in place for the folder.

If the current folder is not within an open Fossil checkout, no errors should be displayed unless the user has tried to do some Fossil action.

I'm using VS Codium on macOS 13.3.

senyai commented 1 year ago

The output is fine but the error message popup is definitely not. Unfortunately I can't reproduce this issue. Can you try other extension versions? And I will try vscodium.

senyai commented 1 year ago

No errors in Vscodium too. I can't think of a reason why an error can popup on these file events.

otherjoel commented 1 year ago

JS is not one of my strengths, but here’s what it looks like to me. Here’s some commands I executed in a non-fossil-checkout folder:

❯ fossil status; echo $?
current directory is not within an open check-out
1

❯ fossil status 2>/dev/null

❯ fossil version; echo $?  
This is fossil version 2.21 [7c71f00ac8] 2022-12-29 17:00:23 UTC
0

Output shows that running fossil status in such a folder outputs to stderr and has a non-zero exit code.

The code in your _exec seems like it will return 'NotAFossilRepository' in this circumstance:

https://github.com/koog1000/vscode-fossil/blob/69a513003f113a9774f9e8eb3f09253aabc9f999/src/fossilExecutable.ts#L404-L411

The logic in calling function exec indicates that control flow will reach throw err; in line 371:

https://github.com/koog1000/vscode-fossil/blob/69a513003f113a9774f9e8eb3f09253aabc9f999/src/fossilExecutable.ts#L359-L371

…and getRepositoryRoot is not catching that thrown exception:

https://github.com/koog1000/vscode-fossil/blob/69a513003f113a9774f9e8eb3f09253aabc9f999/src/fossilExecutable.ts#L335-L348

The exception makes it up to tryOpenRepository which looks like it should catch the error but does nothing with it?

https://github.com/koog1000/vscode-fossil/blob/69a513003f113a9774f9e8eb3f09253aabc9f999/src/model.ts#L302-L328

otherjoel commented 1 year ago

Oh! I just noticed, the error message produced by my version of fossil says check-out whereas your regex uses checkout (without the hyphen):

https://github.com/koog1000/vscode-fossil/blob/69a513003f113a9774f9e8eb3f09253aabc9f999/src/fossilExecutable.ts#L405

So the regex does not match, and that function is actually (probably) returning 'unknown' instead of 'NotAFossilRepository'.

Edit: looks like this changed in this December 2022 commit on the fossil-scm repo: https://fossil-scm.org/home/info/bc36fdcf3acb3114

senyai commented 1 year ago

It must be it. I will be able to release fixed version in 32 hours.