Skip to content

Conversation

raymond-rebbeck
Copy link
Contributor

Fixes #848

Gracefully handle filename or item being empty strings inside ##class(SourceControl.Git.PullEventHandler.IncrementalLoad).DeleteFile()

Commit 7d52f33 causes filename to be an empty string more readily. Which results in the first part of the if statement being executed, if item is an empty string too then ##class(SourceControl.Git.Utils).RemoveRoutineTSH will throw an exception and cause the pull to fail.

As described in fixed issue, was observed with an .xsd file that was present in a Git repo and then deleted. Pull would fail when handling the deletion of this file that had no external or internal name.

Copy link
Contributor

@cambot cambot left a comment

Choose a reason for hiding this comment

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

This is a good fix, but I think you can and should take this a step further.

do ##class(SourceControl.Git.Utils).RemoveRoutineTSH(item)
if (filename = "") || '##class(%File).Exists(filename) {
if (item '= "") {
do ##class(SourceControl.Git.Utils).RemoveRoutineTSH(item)
Copy link
Contributor

Choose a reason for hiding this comment

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

For the sake of completeness, you should also update RemoveRoutineTSH() to validate the input is not null because that is called from a few different places:

ClassMethod RemoveRoutineTSH(InternalName As %String) As %Status
{
    Quit:(InternalName = "") $$$OK
    Set tInternalName = ##class(%Studio.SourceControl.Interface).normalizeName(InternalName)
    Quit:(tInternalName = "") $$$OK
    Kill @..#Storage@("TSH", tInternalName)
    Quit $$$OK
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, it's a good idea and I have implemented it.

The reason I've kept the filename = "" check is because the behaviour of %File.Exists() did not seem to be explicitly defined in the documentation or in the code for a null string input. It seems sensible to me to not bother checking for the existence of a file using a filename when we may not actually have one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good call.

@cambot
Copy link
Contributor

cambot commented Sep 8, 2025

I just tested to verify this PR fixes the issue I reported in #844. I made a branch starting at a point with the bad file name, pushed a commit fixing my config file + renaming the schema file, then running "pull" from the sc menu.

My "Broken" Schema config:

"HL7":{
  "*":{
    "directory":"schemas/hl7"
  }
}

My fixed schema config:

"HL7": {
  "*": {
    "directory": "schemas/hl7/",
    "noFolders": true
  }
}

my "Pull" output:

Pulling from branch: testing/schema-rename
D: schemas/hl7customSchema22/3.hl7
A: schemas/hl7/customSchema22.3.hl7

embedded-git-config.GSC has been imported from C:\InterSystems\FHIR2025\mgr\repo\DEMO\embedded-git-config.json
ERROR #5912: Page '' does not exist
schemas/hl7customSchema22/3.hl7 was deleted.
Importing Item: customSchema22.3.HL7
cnEpcA22.3.HL7 has been imported from C:\InterSystems\FHIR2025\mgr\repo\DEMO\schemas\hl7\customSchema22.3.hl7
Compilation started on 09/08/2025 08:19:59 with qualifiers 'ck'
Compilation finished successfully in 0.011s.

From github.com:StanfordTDS/iris-fhir-server
 * branch            testing/schema-rename -> FETCH_HEAD

Pull ran with return code: 0

Not sure where the "Page does not exist" error is coming from, but that seemed to not matter because after pulling the rename commit, my custom schema had been loaded.

Copy link
Contributor

@cambot cambot left a comment

Choose a reason for hiding this comment

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

I verified this works and also fixes a bug I had reported: #844

@isc-pbarton isc-pbarton linked an issue Sep 10, 2025 that may be closed by this pull request
@isc-pbarton isc-pbarton merged commit 777faba into intersystems:main Sep 10, 2025
@raymond-rebbeck
Copy link
Contributor Author

Not sure where the "Page does not exist" error is coming from, but that seemed to not matter because after pulling the rename commit, my custom schema had been loaded.

The "Page does not exist" error is due to ##class(SourceControl.Git.Utils).Type("") returning "csp". This causes the pull handler to use $System.CSP.DeletePage to try and delete it which fails. This was happening to me before and after this fix and the commit that caused the empty filename with seemingly no ill effect so haven't looked into what a fix might look like.

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.

Pull fails due to deleted xsd file Pull did not import renamed HL7 Schema
3 participants