It appears that ungap-btg cannot be used without erroring if any of the surrounding tiles (N,S,E,W) are 100% water. This is because TerraGear does not produce tiles for an area that is 100% water, like an ocean. TerraSync does not have tiles in these areas either for the same reason.
2 ways I can think of for potential fixes:
Provide just a warning if there is no tile found for either N,S,E,or W, but do not cause a fatal error.
Provide a default "fallback" btg with the tools that would be used in the event that any tile is not found. This would be a flat tile, at sea level, so the script can happily interpolate between the existing tile, and sea level.