KSP-CKAN / CKAN

The Comprehensive Kerbal Archive Network
https://forum.kerbalspaceprogram.com/index.php?/topic/197082-*
Other
1.99k stars 348 forks source link

[Bug] Crash on startup: "System.ArgumentException: Illegal characters in path." #2907

Closed enbyfoxen closed 5 years ago

enbyfoxen commented 5 years ago

Background

Have you made any manual changes to your GameData folder (i.e., not via CKAN)? No

Problem

CKAN closes immediately after opening with the following message displayed in the window:

Unhandled Exception: System.ArgumentException: Illegal characters in path.
   at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
   at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
   at System.IO.Directory.CreateDirectory(String path)
   at CKAN.KSPManager.LoadInstancesFromRegistry()
   at CKAN.CmdLine.MainClass.Execute(KSPManager manager, CommonOptions opts, String[] args)
   at CKAN.CmdLine.MainClass.Main(String[] args)

Steps to reproduce

Expected behavior CKAN should open properly.

Screenshots (if applicable) image

HebaruSan commented 5 years ago

Have you changed the download cache path? The stack trace suggests that it's invalid.

enbyfoxen commented 5 years ago

Have you changed the download cache path? The stack trace suggests that it's invalid.

I assume i would have to do that from inside CKANs settings? CKAN does not open further than the image displayed above.

HebaruSan commented 5 years ago

You can also do it from the command line:

ckan cache list

enbyfoxen commented 5 years ago

Result from attempting to execute the above command on CKAN 1.26.4


.\ckan_orion.exe cache list 
Unhandled Exception: System.ArgumentException: Illegal characters in path. 
at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath) 
at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost) 
at System.IO.Directory.CreateDirectory(String path) 
at CKAN.KSPManager.LoadInstancesFromRegistry() 
at CKAN.CmdLine.Cache.<>c__DisplayClass4_0.<RunSubCommand>b__0(String option, Object suboptions) 
at CommandLine.Parser.ParseArgumentsStrict(String[] args, Object options, Action`2 onVerbCommand, Action onFail) 
at CKAN.CmdLine.Cache.RunSubCommand(KSPManager mgr, CommonOptions opts, SubCommandOptions unparsed) 
at CKAN.CmdLine.MainClass.Execute(KSPManager manager, CommonOptions opts, String[] args) 
at CKAN.CmdLine.MainClass.Main(String[] args)   ```
HebaruSan commented 5 years ago

OK, then we'll need to dig the setting out of the config file (introduced in #2820). It should be in C:\Users\<username>\AppData\Local\CKAN\config.json, possibly with some variations depending on how consistent Microsoft's operating systems are. It should be short enough to paste into a comment from notepad, but have a browse through it first just in case there's any sensitive data (unlikely but not impossible).

enbyfoxen commented 5 years ago

This is the file as it was initially

  "KspInstances": [
    {
      "Name": "Kerbal Space Program",
      "Path": "D:/Games/Kerbal Space Program"
    }
  ],
  "AuthTokens": {},
  "AutoStartInstance": "",
  "DownloadCacheDir": "\\\\?\\C:\\Users\\Luke Antra\\AppData\\Local\\CKAN\\downloads",
  "CacheSizeLimit": null,
  "RefreshRate": 0,
  "KSPBuilds": {
    "builds": {
      "464": "0.23.5.464",
      "559": "0.24.2.559",
      "642": "0.25.0.642",
      "705": "0.90.0.705",
      "830": "1.0.0.830",
      "842": "1.0.2.842",
      "861": "1.0.4.861",
      "1024": "1.0.5.1024",
      "1028": "1.0.5.1028",
      "1172": "1.1.0.1172",
      "1174": "1.1.0.1174",
      "1180": "1.1.0.1180",
      "1183": "1.1.0.1183",
      "1196": "1.1.0.1196",
      "1203": "1.1.0.1203",
      "1209": "1.1.0.1209",
      "1215": "1.1.0.1215",
      "1224": "1.1.0.1224",
      "1228": "1.1.0.1228",
      "1230": "1.1.0.1230",
      "1250": "1.1.1.1250",
      "1260": "1.1.2.1260",
      "1289": "1.1.3.1289",
      "1473": "1.2.0.1473",
      "1479": "1.2.0.1479",
      "1485": "1.2.0.1485",
      "1486": "1.2.0.1486",
      "1489": "1.2.0.1489",
      "1494": "1.2.0.1494",
      "1499": "1.2.0.1499",
      "1500": "1.2.0.1500",
      "1509": "1.2.0.1509",
      "1517": "1.2.0.1517",
      "1520": "1.2.0.1520",
      "1523": "1.2.0.1523",
      "1532": "1.2.0.1532",
      "1539": "1.2.0.1539",
      "1540": "1.2.0.1540",
      "1546": "1.2.0.1546",
      "1548": "1.2.0.1548",
      "1553": "1.2.0.1553",
      "1563": "1.2.0.1563",
      "1564": "1.2.0.1564",
      "1569": "1.2.0.1569",
      "1574": "1.2.0.1574",
      "1576": "1.2.0.1576",
      "1583": "1.2.0.1583",
      "1584": "1.2.0.1584",
      "1586": "1.2.0.1586",
      "1604": "1.2.1.1604",
      "1622": "1.2.2.1622",
      "1727": "1.2.9.1727",
      "1730": "1.2.9.1730",
      "1737": "1.2.9.1737",
      "1738": "1.2.9.1738",
      "1743": "1.2.9.1743",
      "1750": "1.2.9.1750",
      "1758": "1.2.9.1758",
      "1764": "1.2.9.1764",
      "1773": "1.2.9.1773",
      "1781": "1.2.9.1781",
      "1790": "1.2.9.1790",
      "1796": "1.2.9.1796",
      "1800": "1.2.9.1800",
      "1804": "1.3.0.1804",
      "1836": "1.3.1.1836",
      "1847": "1.3.1.1847",
      "1855": "1.3.1.1855",
      "1863": "1.3.1.1863",
      "1891": "1.3.1.1891",
      "2077": "1.4.0.2077",
      "2089": "1.4.1.2089",
      "2110": "1.4.2.2110",
      "2152": "1.4.3.2152",
      "2215": "1.4.4.2215",
      "2243": "1.4.5.2243",
      "2256": "1.4.5.2256",
      "2332": "1.5.0.2332",
      "2335": "1.5.1.2335",
      "2395": "1.6.0.2395",
      "2401": "1.6.1.2401",
      "2483": "1.7.0.2483"
    }
  }
}

This is the file as it was created after i deleted it an ran CKAN Orion

{
  "KspInstances": [
    {
      "Name": "Kerbal Space Program",
      "Path": "C:/Games/Kerbal Space Program"
    }
  ],
  "AuthTokens": {},
  "AutoStartInstance": "Kerbal Space Program",
  "DownloadCacheDir": "\\\\?\\C:\\Users\\Luke Antra\\AppData\\Local\\CKAN\\downloads",
  "CacheSizeLimit": null,
  "RefreshRate": 0,
  "KSPBuilds": {
    "builds": {
      "464": "0.23.5.464",
      "559": "0.24.2.559",
      "642": "0.25.0.642",
      "705": "0.90.0.705",
      "830": "1.0.0.830",
      "842": "1.0.2.842",
      "861": "1.0.4.861",
      "1024": "1.0.5.1024",
      "1028": "1.0.5.1028",
      "1172": "1.1.0.1172",
      "1174": "1.1.0.1174",
      "1180": "1.1.0.1180",
      "1183": "1.1.0.1183",
      "1196": "1.1.0.1196",
      "1203": "1.1.0.1203",
      "1209": "1.1.0.1209",
      "1215": "1.1.0.1215",
      "1224": "1.1.0.1224",
      "1228": "1.1.0.1228",
      "1230": "1.1.0.1230",
      "1250": "1.1.1.1250",
      "1260": "1.1.2.1260",
      "1289": "1.1.3.1289",
      "1473": "1.2.0.1473",
      "1479": "1.2.0.1479",
      "1485": "1.2.0.1485",
      "1486": "1.2.0.1486",
      "1489": "1.2.0.1489",
      "1494": "1.2.0.1494",
      "1499": "1.2.0.1499",
      "1500": "1.2.0.1500",
      "1509": "1.2.0.1509",
      "1517": "1.2.0.1517",
      "1520": "1.2.0.1520",
      "1523": "1.2.0.1523",
      "1532": "1.2.0.1532",
      "1539": "1.2.0.1539",
      "1540": "1.2.0.1540",
      "1546": "1.2.0.1546",
      "1548": "1.2.0.1548",
      "1553": "1.2.0.1553",
      "1563": "1.2.0.1563",
      "1564": "1.2.0.1564",
      "1569": "1.2.0.1569",
      "1574": "1.2.0.1574",
      "1576": "1.2.0.1576",
      "1583": "1.2.0.1583",
      "1584": "1.2.0.1584",
      "1586": "1.2.0.1586",
      "1604": "1.2.1.1604",
      "1622": "1.2.2.1622",
      "1727": "1.2.9.1727",
      "1730": "1.2.9.1730",
      "1737": "1.2.9.1737",
      "1738": "1.2.9.1738",
      "1743": "1.2.9.1743",
      "1750": "1.2.9.1750",
      "1758": "1.2.9.1758",
      "1764": "1.2.9.1764",
      "1773": "1.2.9.1773",
      "1781": "1.2.9.1781",
      "1790": "1.2.9.1790",
      "1796": "1.2.9.1796",
      "1800": "1.2.9.1800",
      "1804": "1.3.0.1804",
      "1836": "1.3.1.1836",
      "1847": "1.3.1.1847",
      "1855": "1.3.1.1855",
      "1863": "1.3.1.1863",
      "1891": "1.3.1.1891",
      "2077": "1.4.0.2077",
      "2089": "1.4.1.2089",
      "2110": "1.4.2.2110",
      "2152": "1.4.3.2152",
      "2215": "1.4.4.2215",
      "2243": "1.4.5.2243",
      "2256": "1.4.5.2256",
      "2332": "1.5.0.2332",
      "2335": "1.5.1.2335",
      "2395": "1.6.0.2395",
      "2401": "1.6.1.2401",
      "2483": "1.7.0.2483",
      "2539": "1.7.1.2539",
      "2555": "1.7.2.2555",
      "2556": "1.7.2.2556",
      "2594": "1.7.3.2594",
      "2686": "1.8.0.2686"
    }
  }
}

I then changed "\\\\?\\C:\\Users\\Luke Antra\\AppData\\Local\\CKAN\\downloads" to "C:\\Users\\Luke Antra\\AppData\\Local\\CKAN\\downloads"

And now CKAN Orion works.

However, deleting the file again and executing CKAN Orion recreates the file with the malformed path. Causing the issue to reappear.

HebaruSan commented 5 years ago

Yeah, that's definitely the cause, Windows doesn't allow question marks in paths. https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file

As for why it comes back after deleting the file, you probably have some old registry keys from previous versions that are being imported. Check HKEY_CURRENT_USER\Software\CKAN in regedit.

enbyfoxen commented 5 years ago

DownloadCacheDir (REG_SZ) is set to \\?\C:\Users\Luke Antra\AppData\Local\CKAN\downloads

Deleting this entry makes the problem now go away entirely.

Thank you for the help!

HebaruSan commented 5 years ago

Great to hear! I guess we ought to add (more) validation of that field...

DasSkelett commented 5 years ago

https://docs.microsoft.com/de-de/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#maximum-path-length-limitation

Those are extended-length paths. From what I read, they are per se valid (and theoretically shouldn't make any problems), but it looks like we are doing some (de)serialization escaping wrong.

HebaruSan commented 5 years ago

:man_facepalming::boom: