ModelicaStandardLibrary icon indicating copy to clipboard operation
ModelicaStandardLibrary copied to clipboard

Improve error handling of loadResource()

Open GarronFish opened this issue 3 years ago • 1 comments

Currently when Modelica.Utilities.Files.loadResource() is used with a URL that is not found the URL is returned. It would be useful if a status flag was also returned and the directory for the resource returned was an empty string.

For example: Modelica.Utilities.Files.loadResource("modelica:\ThisURLIsNot\An\Existing\File\OrDirectory") currently would return: "modelica:\ThisURLIsNot\An\Existing\File\OrDirectory"

An improvement would be: (resourcePath,status)=Modelica.Utilities.Files.loadResource("modelica:\ThisURLIsNot\An\Existing\File\OrDirectory"); would return: resourcePath="" status=false

This ticket is requested by a Dymola customer that thought that the error handling of loadResource() should be improved.

GarronFish avatar Apr 01 '22 18:04 GarronFish

Unless this is an issue reported for a particular tool and an actual implementation of ModelicaServices, could the real problem here be that the MSL's template implementation should always fail with a suitable error message rather than having this weird dummy behavior: https://github.com/modelica/ModelicaStandardLibrary/blob/80325f858b3a3fc9879f0a933a821a608a5afcd4/ModelicaServices/package.mo#L168

For example, this would make more sense to me in the template definition:

    function loadResource
      "Dummy implementation of Modelica.Utilities.loadResource."
      extends
        Modelica.Utilities.Internal.PartialModelicaServices.ExternalReferences.PartialLoadResource;
    algorithm
      assert(false, "Illegal attempt to use dummy implementation of loadResource.");

henrikt-ma avatar Apr 02 '22 20:04 henrikt-ma