Skip to content

CSP: Failed to save file '...' on the server #1345

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

Closed
cvertee opened this issue Apr 10, 2024 · 18 comments
Closed

CSP: Failed to save file '...' on the server #1345

cvertee opened this issue Apr 10, 2024 · 18 comments

Comments

@cvertee
Copy link

cvertee commented Apr 10, 2024

For some reason i get 'Failed to save file *.csp on the server' error in VSCode. Sometimes it does work, sometimes it doesn't. Even if i try to edit the same file i can get lucky and successfully compile it. But this probability is heavily random and can't figure out why this happens from time to time.
In the Output tab ObjectScript writes successful compiles or errors while compiling CLS files. But when such save error happens in CSP file there is just nothing.

Language Server Output with verbose level only writes this when saving, no errors (uri contains path to file://)

Sending notification 'textDocument/didSave'.
Params: {
    "textDocument": {
        "uri": "..."
    }
}

IRIS Version: 2020.1
VSCode Version: 1.87.2
OS: Windows 10

@cvertee
Copy link
Author

cvertee commented Apr 10, 2024

Sometimes even after successful CSP compile, whenever i add something like alert(1) and hit save it just starts giving errors. Super rarely can fix this by adding spaces after/before html tags.
Line count of errored file is ~1500 but sometimes can't compile files under 300-500 lines.

@cvertee
Copy link
Author

cvertee commented Apr 10, 2024

Looks like it doesn't check contents of the file on the server because whenever i add syntax errors etc it doesn't say anything about that. Maybe some issues with processing file locally?

@isc-bsaviano
Copy link
Contributor

@cvertee The Language Server plays no role in the saving of documents so that log isn't going to help us. For local files, this extension determines the name of the CSP file by seeing if the file's path contains a web application name, and then saves the file on the server with the file's name begin the path starting at the web application folder name. For example, if you had file src/csp/user/menu.csp in your workspace and saved it, this extension would tell the server that the document name is csp/user/menu.csp. CSP saves can fail if this name is wrong. The best way to check the cause of the save failure is to get a network trace using a tool like Wireshark so we can see the REST request and response packets.

@cvertee
Copy link
Author

cvertee commented Apr 11, 2024

@isc-bsaviano thanks for the response! Not sure if i will be able to use Wireshark. Maybe will think of something for corporate computer stuff

@isc-bsaviano
Copy link
Contributor

@cvertee You can use the web gateway's HTTP Trace facility. It doesn't require you to download any other software. The UI and functionality is rudimentary but it will get the info we need to investigate this. See the web gateway management pages docs and the HTTP Trace docs.

@cvertee
Copy link
Author

cvertee commented Apr 12, 2024

@isc-bsaviano Will try to look on that (or something else) later when i'll find the time, thanks.

@isc-bsaviano
Copy link
Contributor

Hi @cvertee, just checking in to see if the trace revealed anything.

@cvertee
Copy link
Author

cvertee commented Apr 18, 2024

@isc-bsaviano Hi. Not working with IRIS for now. Tried to get to Web Gateway but probably nobody will let me get there (not the admin and whatever) so still thinking on possible workarounds

@isc-bsaviano
Copy link
Contributor

Closing this since I can't reproduce it. @cvertee please re-open if you find reliable reproduction steps.

@isc-bsaviano isc-bsaviano closed this as not planned Won't fix, can't repro, duplicate, stale May 2, 2024
@cvertee
Copy link
Author

cvertee commented Nov 19, 2024

Not sure if its somehow related. But whatever. I had csp file that just did not compile with vs code extension (same problem as described WITHOUT any description/details)
But i found out something in source code related to base64 chunk sizes and tried to find problematic place in code (by deleting code and finding out which removed code make it work)
So i found something like

window.onload = function() {

At probably exactly 12981 or 12982 character (vs code's "selected" count when i select from this symbol to start of file)

window.onload = function() {
// ----------^ here

when i move

 = function() {

at new line CSP file starts to compile

When i put it back, CSP again shows compile error, moving to new line and it works again, etc

Still can't say if its something problematic on the server or extension have some problems with chunk sizes???

@cvertee
Copy link
Author

cvertee commented Nov 19, 2024

@isc-bsaviano

@isc-bsaviano
Copy link
Contributor

@cvertee You are using client-side editing correct? csp files shouldn't be converted to base64 since they are text files. If they are, then that's a bug in this extension. Are you able to get a network trace like I mentioned above? If not, can you send me a test file I can use to reproduce this on my end?

@cvertee
Copy link
Author

cvertee commented Nov 19, 2024

@isc-bsaviano Yeah i edit file from the client (i guess) side, and can't send it here. About tracing kinda trying to think of something. Not even sure it'll help because if there is an error on server compiler it should return something to display in at least the VSCode output, no?
Also maybe it'll be a good idea to add verbose log like in language server, so someone can easily see what happens/what json is returned during saving or other stuff, cause who knows maybe we'll see nothing in WebGateway or whatever.

@isc-bsaviano
Copy link
Contributor

@cvertee Compilation errors will appear in the Output window. Errors saving a file should as well, but if VS Code doesn't get a detailed error message back from the server then it won't Output anything. I will consider adding a setting that turns on logging for REST requests.

I tried to reproduce your issue again but couldn't. Without more info there's not much I can do. You can try opening an issue with the WRC. They will be able to screen share with you and their app is a secure way to share files.

@cvertee
Copy link
Author

cvertee commented Nov 19, 2024

@isc-bsaviano Thanks!

@cvertee
Copy link
Author

cvertee commented Nov 21, 2024

@isc-bsaviano finally sorted things out with WebGateway, i enabled HTTP tracing, saw that some csp sends /api/atelier/v3 PUT request with content NOT being base64 encrypted and this csp compiles succesfully without any troubles.
But when i do the same with the bad csp file (that doesn't give any error details) no PUT request is traced (i guess). No thing that looks like PUT /api/atelier, only some basic GET to /api/atelier for whatever reason (probably not related to this problem)

But when i go to the event log i can find something interesting, the name of the csp file that can't compile, part of the content and error
Error Condition: Failed to read posted content from the client (Content-Length: 16229; Data Actually Read: 899; Read Error: 730054)

Another bad csp file error
Error Condition: Failed to read posted content from the client (Content-Length: 21055; Data Actually Read: 7446; Read Error: 730054)

@cvertee
Copy link
Author

cvertee commented Nov 21, 2024

What's more interesting is that i can edit file, remove some lines or whatever but it still gives the same 899 of Data Actualy Read
Can even see that the JSON in the event log is changing after each file edit
For some reasons file cuts itself to 899 or 7446 characters?

@isc-bsaviano
Copy link
Contributor

@cvertee Thanks for the information. Unfortunately, I'm not an expert on the web gateway or CSP. If you haven't already, I suggest you open a WRC case and give them a link to this issue and the $ZV of your server. It's probably pretty old since it only has Atelier API v3 (v4 was added in IRIS 2019.1 and Cache 2018.1.5?) so maybe this is a known CSP bug that's fixed in a later version. If you don't have WRC access then you can post this on the Developer Community (https://community.intersystems.com/) and someone there may be able to help.

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