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

Ledger demo: windows path problems #41

Open
maphew opened this issue Sep 12, 2021 · 15 comments
Open

Ledger demo: windows path problems #41

maphew opened this issue Sep 12, 2021 · 15 comments

Comments

@maphew
Copy link

maphew commented Sep 12, 2021

I just discovered Jsish and am in the process of understanding the landscape.

Following https://docs.jsish.org/Demos.md I get:

D:\> jsish -a jsi-app.fossil Ledger                                                               
mopts { file:"jsi-app.fossil", noPatches:false, type:"fossil", version:"" }                    
CALL BACKTRACE:                                                                                
#1: Archive.jsi:108:  in moduleRun( "jsi-app.fossil", "Ledger" )                               
#2: Archive.jsi:105:  in Archive( [ "jsi-app.fossil", "Ledger" ], {} )                         
#3: Archive.jsi:16:  in moduleRun()                                                            
#4: Ledger.jsi:1696:  in Ledger( [], {} )                                                      
#5: Ledger.jsi:1597:  in main()                                                                
#6: Ledger.jsi:133:  in createDb( 0, "C:/Users/mhwilkie/LedgerJsi/ledgerjs.db" )               
                                                                                               
Ledger.jsi:133: error: db open failed: C:\Users\mhwilkie\code/C:/Users/mhwilkie/LedgerJsi/ledge
rjs.db    (c-extn [Sqlite])                                                                    
ERROR:                                                                                         

It looks like a problem merging current directory with HOMEDRIVE and HOMEPATH .

@maphew
Copy link
Author

maphew commented Sep 12, 2021

Relatedly, the online demos (https://docs.jsish.org/Demos.md#online) yield 502 Bad Gateway error. I'm happy to log that as a distinct issue if you'd prefer things broken out into distinct items. (I don't want to create too much noise while I'm still in exploration phase and not sure if this project matches my project enough to also stay around help fix things.)

@maphew
Copy link
Author

maphew commented Sep 12, 2021

I tried opening the fossil repo and setting jsi-app\Ledger\Ledger.jsi line defaultDBFile: to various relative and absolute paths but that didn't work. Jsish always prepends the current path to the defaultDBFile path. For example:

defaultDbFile:'C:/Users/mhwilkie/code/LedgerJsi/ledgerjs.db',
C:\> jsish "C:\Users\mhwilkie\code\jsi-app\Ledger\Ledger.jsi"
error: File open failed 'C:/C:/Users/mhwilkie/code/jsi-app/Ledger/Ledger.jsi'
ERROR:

I also tried running from mingw bash shell with the original default path of ~/LedgerJsi/Ledgerjs.db but same error.

@pcmacdon
Copy link
Owner

Re: 502
I just visited https://docs.jsish.org/Demos.md#online and saw no problem.
Could this just be a transient network problem?

@pcmacdon
Copy link
Owner

Hi and thanks for the bug reports.
Jsish windows support is rudimentary at best, and it is easy to make it fail.
In this case, you hit the nail on the head. It seems HOMEDRIVE is the source of the problem in the "realpath()" call because it is expected to be a drive letter "C:", but looks to be a path instead. You could verify by commenting it out at Ledger.jsi:1590: eg:

# self.dbfile = File.realpath(self.dbfile);

@maphew
Copy link
Author

maphew commented Sep 13, 2021

Well we have progress! After commenting out line 1590 it get's past the default db setup and launches a browser. It's not working yet but I have a trail to follow through the thorn patch. I've spent a lot of hours learning how to handle cross platform paths in Python so once I get a handle on the Js(i) view of the world I might be able to help solidify these parts.

Matt@SERVER D:\Matt\code\jsi\jsi-app
$ jsish Ledger\Ledger.jsi
Ledger.jsi:169:  "WARN: Updating DB schema version from 0", createDb()
CALL BACKTRACE:
#1: Ledger.jsi:16:  in moduleRun()
#2: Ledger.jsi:1696:  in Ledger( [], {} )
#3: Ledger.jsi:1690:  in main()

D:/Matt/code/jsi/jsi-app/Ledger/Ledger.jsi:1690: error: JSON parse error (unexpected symbol) at offset 1 ""D:/\Matt\code\jsi\jsi-app/D:/"
Ledger.jsi:1220: "WARN: fossil not found", FossilBackup()

@maphew
Copy link
Author

maphew commented Sep 13, 2021

How to see the LogDebug messages? e.g. I tried adding a couple of lines to report what's going on but they're not being echoed to the starting shell. (Feel free to direct me elsewhere if this is too basic a question for here. I am learning how to use the web debugger (so cool!) but that hasn't revealed anything to me yet.)

Starting at line Ledger.jsi:1588

        if (self.dbfile === '' || self.dbfile === undefined)
            self.dbfile = self.defaultDbFile;
            LogDebug("self.dbfile Before:" + self.dbfile);        
            self.dbfile = File.realpath(self.dbfile);
        LogDebug("self.dbfile: After" + self.dbfile);

@pcmacdon
Copy link
Owner

Add the "-Debug" option to the command:

jsish -a jsi-app.fossil Ledger -Debug 1

@maphew
Copy link
Author

maphew commented Sep 14, 2021

It's not the realpath() line. Debug shows createDb is using a correctly formed Windows path. It looks like it's the Sqlite() call that's prepending current dir.

$ jsish Ledger\Ledger.jsi -Debug 1
Ledger.jsi:1591: "DEBUG: self.dbfile Before: ~/LedgerJsi/ledgerjs.db", main()
Ledger.jsi:1593: "DEBUG: self.dbfile: After: C:/Users/mhwilkie/LedgerJsi/ledgerjs.db", main()
Ledger.jsi:1599: "DEBUG: using db file: C:/Users/mhwilkie/LedgerJsi/ledgerjs.db", main()
Ledger.jsi:131:  "DEBUG: CreateDb:fd: C:/Users/mhwilkie/LedgerJsi", createDb()
CALL BACKTRACE:
#1: Ledger.jsi:16:  in moduleRun( "-Debug", "1" )
#2: Ledger.jsi:1699:  in Ledger( [], { Debug:1 } )
#3: Ledger.jsi:1600:  in main()
#4: Ledger.jsi:134:  in createDb( 0, "C:/Users/mhwilkie/LedgerJsi/ledgerjs.db" )

Ledger.jsi:134: error: db open failed: C:\Users\mhwilkie\code\jsi-app/C:/Users/mhwilkie/LedgerJsi/ledgerjs.db    (c-extn [Sqlite])
ERROR:

ledger-debug-path.txt

@pcmacdon
Copy link
Owner

Ah, I was misled by your statement about HOMEPATH etc.
Yes, it looks like the culprit in this case is jsiSqlite.c call to Jsi_ValueNormal,
which leads to Jsi_NormalPath in jsiFilesys.c:1204, which is unable to handle Windows drive letter madness as indicated by the comment:

// TODO: add proper handling for windows paths.

Path normalization is particularly difficult. Will have to look at it tomorrow.

@maphew
Copy link
Author

maphew commented Sep 14, 2021

thank you for the attention; I imagine you had other designs on your focus today! In my attempts to wrest my brain into sense making I landed in the same file, but was spelunking in Jsi_FileRealpathStr() instead. I still don't understand C, but the gist is far clearer to me than it was a few years ago. Likely you don't need it, but in case it's helpful: my searching led to python's posixpath lib as a battle tested help with the logic (by way of Roman Susi).

@pcmacdon
Copy link
Owner

pcmacdon commented Sep 14, 2021

There was code in Jsi_NormalPath to handle this case, but it was commented out. If there was a reason why, I can not remember. So I've uncommented it. Can you rebuild and give it a retry? I've also rebuilt the windows download: http://jsish.org/bin/jsish.exe

@maphew
Copy link
Author

maphew commented Sep 14, 2021

Yes! That works. Thank you. I used the jsish.org binary as I don't have a C build system yet.

image

A niggle: there's mistaken a message about not being in current checkout. Maybe that has something to do with why the section was commented out.

Matt@SERVER D:\Matt\code\jsi\jsi-app
$ fossil sync
Sync with https://jsish.org/fossil/jsiapp/
Round-trips: 1   Artifacts sent: 0  received: 0
Sync done, wire bytes sent: 1897  received: 1934  ip: 50.116.0.90

Matt@SERVER D:\Matt\code\jsi\jsi-app
$ jsish Ledger\Ledger.jsi
Ledger.jsi:169:  "WARN: Updating DB schema version from 0", createDb()
current directory is not within an open checkout
current directory is not within an open checkout

btw, very nice touch that jsi exits when the browser window closes. I've not seen any other local web server app do that.

@maphew
Copy link
Author

maphew commented Sep 15, 2021

Relative path works but not absolute. I can work around this, it doesn't block me, but now is noted as current limitation.

$ jsish -v
3.5.0 3.05 f6e85cbd1fdeb58afeac16c7c68a61b1e260c2d9 2021-09-14 14:17:34 UTC

Matt@SERVER D:\Matt\www\maphew.com-fossil\ckout
$ jsish %cd%\make-index.jsi -Debug 1
error: File open failed 'D:/Matt/www/maphew.com-fossil/ckout/D:/Matt/www/maphew.com-fossil/ckout/make-index.jsi'
ERROR:

Matt@SERVER D:\Matt\www\maphew.com-fossil\ckout
$ jsish .\make-index.jsi -Debug 1
[ "blog/About_Maphew.md", "blog/Batch/call-ss64-com-for-help.md" ...snip... ]

Where make-index.jsi is just:

var docs = File.glob('*.md', {recurse:true});
puts(docs);

@pcmacdon
Copy link
Owner

OK, I've commited a fix, if you'd like to download the jsish.exe and try it out.

@maphew
Copy link
Author

maphew commented Sep 16, 2021

+1 it works. Thank you

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

No branches or pull requests

2 participants