Skip to content

Settingsloader: Fail on Error#633

Open
SmithChart wants to merge 2 commits into
lona-web-org:masterfrom
SmithChart:settingsloader-fail-on-error
Open

Settingsloader: Fail on Error#633
SmithChart wants to merge 2 commits into
lona-web-org:masterfrom
SmithChart:settingsloader-fail-on-error

Conversation

@SmithChart

Copy link
Copy Markdown
Contributor

Loading settings is a very early step when starting up Lona. In case that a settings file or a settings override can not be loaded or parsed Lona currently continues to start. But will very likely not be configured in a way that the user expect or want. For example:

$ lona run-server -s does_not_exist.py
MainThread                     ERROR    11:39:42.919306 lona.settings exception raised while loading settings '/home/chris/(...)/does_not_exist.py'
  Traceback (most recent call last):                                                                                                                                                                                                                                                                                
    File "/home/chris/(...)/env/lib/python3.13/site-packages/lona/settings.py", line 26, in add                                                                                                                                                                                         
      values = runpy.run_path(                                                                                                                                                                                                                                                                                      
          path,                                                                                                                                                                                                                                                                                                     
          init_globals=self._values,                                                                                                                                                                                                                                                                                
          run_name=path,                                                                                                                                                                                                                                                                                            
      )                                                                                                                                                                                                                                                                                                             
    File "<frozen runpy>", line 286, in run_path                                                                                                                                                                                                                                                                    
    File "<frozen runpy>", line 254, in _get_code_from_file                                                                                                                                                                                                                                                         
  FileNotFoundError: [Errno 2] No such file or directory: '/home/chris/(...)/does_not_exist.py'                                                                                                                                                                                         
MainThread                     WARNING  11:39:42.920526 lona.server routing table is empty
/home/chris/(...)/env/lib/python3.13/site-packages/lona/templating.py:44: Lona_2_0_DeprecationWarning: client_version() will be removed in 2.0
  lona.warnings.remove_2_0()
======== Running on http://localhost:8080 ========
(Press CTRL+C to quit)

With this change Lona will simply refuse to start up and exit with rc=1.
This way a script or service running Lona can catch and report the misconfiguration:

lona run-server -s does_not_exist.py; echo $?
MainThread                     ERROR    11:31:59.257469 lona.settings exception raised while loading settings '/home/chris/(...)/does_not_exist.py'
  Traceback (most recent call last):                                                                                                                                                                                                                                                                                
    File "/home/chris/(...)/env/lib/python3.13/site-packages/lona/settings.py", line 27, in add                                                                                                                                                                                         
      values = runpy.run_path(                                                                                                                                                                                                                                                                                      
          path,                                                                                                                                                                                                                                                                                                     
          init_globals=self._values,                                                                                                                                                                                                                                                                                
          run_name=path,                                                                                                                                                                                                                                                                                            
      )                                                                                                                                                                                                                                                                                                             
    File "<frozen runpy>", line 286, in run_path                                                                                                                                                                                                                                                                    
    File "<frozen runpy>", line 254, in _get_code_from_file                                                                                                                                                                                                                                                         
  FileNotFoundError: [Errno 2] No such file or directory: '/home/chris/(...)/does_not_exist.py'                                                                                                                                                                                         
1

@SmithChart SmithChart force-pushed the settingsloader-fail-on-error branch from 480e167 to 2ef0403 Compare April 2, 2026 10:51
@SmithChart

SmithChart commented Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

It has been some time since we had any activity on this project :-)

So: Before I start wrestling the rest of the CI failures here: Is there any interesting in merging fixes like this and maybe even make a new release of Lona?

@fscherf

fscherf commented Apr 2, 2026

Copy link
Copy Markdown
Member

Hey @SmithChart!

Long time no see :) thx for this fix!

Absolutely! You are right, traffic on this project was pretty low for a long time now, but only because it is (somewhat) done 🤷 It does everything that I needed it to do and it never stopped working. I still get emails from people with questions regulary, so people never stopped using it.

I'd be happy to release a new version for you after we get this PR merged.

When parsing settings overrides from the command line fails, Lona starts
up just fine.
This leads to situations where Lona may start up, but is actually running
with an unexpected configuration.

With this change Lona will exit with return code 1 if parsing of an
override failed.

Signed-off-by: Chris Fiege <cfi@pengutronix.de>
When loading a settings file provided on the command line fails Lona
only logs an error but will start up just fine.
This leads to situations where Lona may start up, but is actually running
with an unexpected configuration.

With this change Lona will exit with return code 1 if a settings file
could not be loaded.

Signed-off-by: Chris Fiege <cfi@pengutronix.de>
@fscherf fscherf force-pushed the settingsloader-fail-on-error branch from 2ef0403 to fbdafc1 Compare April 23, 2026 17:48
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.23%. Comparing base (0ff6921) to head (fbdafc1).
⚠️ Report is 92 commits behind head on master.

Files with missing lines Patch % Lines
lona/command_line/handle_command_line.py 0.00% 2 Missing ⚠️
lona/settings.py 33.33% 2 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #633      +/-   ##
==========================================
+ Coverage   73.12%   73.23%   +0.10%     
==========================================
  Files          88       88              
  Lines        6128     6130       +2     
  Branches     1328     1328              
==========================================
+ Hits         4481     4489       +8     
+ Misses       1364     1361       -3     
+ Partials      283      280       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fscherf

fscherf commented Apr 23, 2026

Copy link
Copy Markdown
Member

@SmithChart I fixed the CI problems.
In general, I agree with the patches, I'm not sure whether doing a hard sys.exit in a high-level module like settings is the right thing to do here. Ideally, we would raise a special exception there that is then handled by the cli code by issuing sys.exit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants