grass icon indicating copy to clipboard operation
grass copied to clipboard

[Bug] grass -c fails if database, project does not exist.

Open marisn opened this issue 10 months ago • 3 comments

Describe the bug

The description of grass -c reads: create given database, project or mapset if it doesn't exist. If I pass non-existing database, project and mapset thus I do expect that those will be created, but instead a Python error is thrown as the code expects database and project to exist.

To reproduce

grass -c epsg:10306 grassdb/lks2020/reproj
Starting GRASS...
Creating new GRASS project <reproj>...
Traceback (most recent call last):
  File "/home/marisn/soft/./grass-marisn/bin.x86_64-pc-linux-gnu/grass", line 2460, in <module>
    main()
    ~~~~^^
  File "/home/marisn/soft/./grass-marisn/bin.x86_64-pc-linux-gnu/grass", line 2332, in main
    set_mapset(
    ~~~~~~~~~~^
        gisrc=gisrc, arg=params.mapset, geofile=params.geofile, create_new=True
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/marisn/soft/./grass-marisn/bin.x86_64-pc-linux-gnu/grass", line 876, in set_mapset
    create_location(gisdbase, location_name, geofile)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/marisn/soft/./grass-marisn/bin.x86_64-pc-linux-gnu/grass", line 696, in create_location
    gcore.create_location(
    ~~~~~~~~~~~~~~~~~~~~~^
        gisdbase, location, epsg=epsg, datum_trans=datum_trans
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/marisn/soft/grass-marisn/dist.x86_64-pc-linux-gnu/etc/python/grass/script/core.py", line 1762, in create_location
    return create_project(*args, **kwargs)
  File "/home/marisn/soft/grass-marisn/dist.x86_64-pc-linux-gnu/etc/python/grass/script/core.py", line 1804, in create_project
    os.mkdir(mapset_path.directory)
    ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/marisn/soft/grassdb/lks2020'

Expected behavior

Command behavior matches documentation.

System description

No version info, as it was tested on one of active PRs on a Linux box.

marisn avatar Jun 09 '25 11:06 marisn

Present in ad6e958c27a6ed7228e3cf7c40a2a63ea9949c58

marisn avatar Jun 09 '25 15:06 marisn

At this point, I would say the documentation is wrong, not code. Specifically, it is the --help message which is wrong saying:

  -c                             create given database, project or mapset if it doesn't exist

The documentation says that -c creates a project or mapset:

Image

I would keep the current behavior specified in the documentation also because I think we should emphasize less the directory with projects in our interfaces. The issue Rename location to project #3121, Phase 3, point 2 says:

De-emphasize GISDBASE as its own thing from user perspective. Gisdbase (GISDBASE, gisdbase) was never really readable. Presenting it as simply the directory when one or more projects (locations) are might be sufficient. The directory can still be treated in a special way as it is now, e.g., in command line, it is easier to switch to mapset in another project (location) in the same gisdbase than it is in another gisdbase. For example, grass.script.setup.init calls the parameter path and not gisdbase.

The traceback is not ideal, and it should be replaced by a printed error, probably by checking ahead for a nice message and then capturing this and other exceptions from create_project.

wenzeslaus avatar Jun 09 '25 20:06 wenzeslaus

I do not advocate for any solution, just that there should be an user friendly error message and a correct message in --help output.

marisn avatar Jun 10 '25 06:06 marisn