Skip to content

startup: Report clear error instead of traceback when -c fails - #8034

Open
Akash324-dotcom wants to merge 2 commits into
OSGeo:mainfrom
Akash324-dotcom:fix-grass-c-missing-db
Open

Akash324-dotcom wants to merge 2 commits into
OSGeo:mainfrom
Akash324-dotcom:fix-grass-c-missing-db

Conversation

@Akash324-dotcom

Copy link
Copy Markdown
  • Removed "database" word from -c help text.
  • the except error was looking for gs.ScriptError, which does not exist, so even the normal errors crashed with an AttributeError; now it imports ScriptError from the grass.exceptions.
  • added except OSError so the missing folders give the clear message.

Fixes #5865. I followed @wenzeslaus's suggestion in the issue (fix the help text, show an error instead of the traceback). I found the ScriptError problem while reproducing the bug.

Note: GRASS still creates the database directory if only that one level is missing. The crash happened when more than one level was missing.

Tested how
Built with CMake on Ubuntu (WSL).

Missing directories, before:

FileNotFoundError: [Errno 2] No such file or directory: '/home/akash/nodb_test/deeper'
...
AttributeError: module 'grass.script' has no attribute 'ScriptError'

After:

ERROR: Cannot create project <myproject>: No such file or directory: /home/akash/nodb_test/deeper

Invalid EPSG (-c EPSG:99999999), before: same AttributeError traceback. After:

ERROR: Error creating project:
ERROR: Value <99999999> out of range for parameter <epsg>

Added lib/init/testsuite/test_grass_create_project.py. I checked that it fails without the fix and passes with it.

Type of fix

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • PR title provides summary of the changes and starts with one of the pre-defined prefixes
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@github-actions github-actions Bot added Python Related code is in Python libraries tests Related to Test Suite labels Oct 8, 2026
Comment thread lib/init/testsuite/test_grass_create_project.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants