stevieb9 / berrybrew

Perlbrew for Windows!
Other
63 stars 9 forks source link

Uncaught exception when writing perls_custom.json when removing custom perl #335

Closed stevieb9 closed 11 months ago

stevieb9 commented 11 months ago
C:\repos\berrybrew>staging\bb register steve
IN DEV MODE
Successfully registered steve

C:\repos\berrybrew>staging\bb remove steve
IN DEV MODE
Removing Strawberry Perl steve
Successfully removed Strawberry Perl steve

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at BerryBrew.Berrybrew.JsonWrite(String type, List`1 data, Boolean fullList)
   at BerryBrew.PerlOperations.PerlOp.PerlRemove(String perlVersionToRemove)
   at berrybrew.Bbconsole.Main(String[] args)
stevieb9 commented 11 months ago

It appears as though if the perl being removed is the last one in the perls_custom.json file, the process will succeed. ie, if the perl being removed causes the file to become an empty list, all is well. If there's a write of a still-installed custom perl, it fails

stevieb9 commented 11 months ago

Here is what the custom perl json looks like after importing two snapshots (ie. custom perls):

[
  {
    "name": "test",
    "custom": false,
    "file": null,
    "url": null,
    "ver": null,
    "csum": null
  },
  {
    "name": "steve",
    "custom": false,
    "file": null,
    "url": null,
    "ver": null,
    "csum": null
  }
]
stevieb9 commented 11 months ago

The fix was to assign an empty string to the values of the Strawberry Perl object if the values we try to assign are null:

data["url"]     = perlBase.Url ?? "";

Also, after that fix, ver didn't behave properly because the version sorter in BB.JsonWrite() requires a string of three integers, separated by two decimal points. The empty string caused that code to throw:

data["ver"] = perlBase.Version ?? "0.0.0";