Skip to content

Fix app crash on selecting unavailable layer, Add info message - #4718

Open
xkello wants to merge 1 commit into
masterfrom
bugfix/fix-unavailable-layer-crash
Open

xkello wants to merge 1 commit into
masterfrom
bugfix/fix-unavailable-layer-crash

Conversation

@xkello

@xkello xkello commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Description

Tapping a layer that failed to load (bad PostGIS credentials, offline server, missing local file, etc.) crashed the app instead of telling the user anything useful.

Fixes: #4568

What changed

  • LayerFeaturesModel::populate() now checks isValid() before querying the layer's data provider. This was the actual cause of the crash, since a broken connection still has a non-null dataProvider().
  • LayerDetailData gained an isValid property so QML knows whether the tapped layer actually loaded, and logs the real failure reason internally (via CoreUtils::log) without exposing it to the user.
  • MMLayerDetailPage.qml now shows a generic "Layer unavailable" screen (with a normal header/back button) instead of building the features list and legend when the layer is invalid.
  • ActiveProject::validateProject() now logs the underlying error reason alongside the existing Project Issues entry, for easier debugging.

Behaviour

Before: tapping an unavailable layer crashed the app.
After: the user sees a "Layer unavailable" message and can navigate back normally; the specific reason (auth failure, offline, missing file, etc.) is only written to the log.

Screenshots

Before After
image IMG_4862

@xkello
xkello requested a review from Withalion September 24, 2026 15:06
@github-actions

Copy link
Copy Markdown

Coverage Report for CI Build 36016602754

Coverage decreased (-0.01%) to 59.501%

Details

  • Coverage decreased (-0.01%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 93 coverage regressions across 2 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

93 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
mm/app/activeproject.cpp 58 71.04%
mm/app/layer/layerdetaildata.cpp 35 57.14%

Coverage Stats

Coverage Status
Relevant Lines: 15751
Covered Lines: 9372
Line Coverage: 59.5%
Coverage Strength: 94.01 hits per line

馃挍 - Coveralls

@tomasMizera tomasMizera left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! I left a minor comment about ternary operators. Once fix, please proceed to testing without my review :)

Comment thread app/activeproject.cpp
Comment on lines +303 to +306
QgsError layerError = layer->error();
const QString reason = !layerError.isEmpty() ? layerError.summary()
: ( layer->dataProvider() ? layer->dataProvider()->error().summary() : QString() );
CoreUtils::log( QStringLiteral( "Project load" ), QStringLiteral( "Invalid layer %1: %2" ).arg( layer->name(), reason ) );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not nest multiple ternary operators. They become quite hard to read.

Try comparing it with this

Suggested change
QgsError layerError = layer->error();
const QString reason = !layerError.isEmpty() ? layerError.summary()
: ( layer->dataProvider() ? layer->dataProvider()->error().summary() : QString() );
CoreUtils::log( QStringLiteral( "Project load" ), QStringLiteral( "Invalid layer %1: %2" ).arg( layer->name(), reason ) );
QgsError layerError = layer->error();
QString reason;
if ( !layerError.isEmpty() )
{
reason = layerError.summary();
}
else if ( layer->dataProvider() )
{
reason = layer->dataProvider()->error().summary();
}
CoreUtils::log( QStringLiteral( "Project load" ), QStringLiteral( "Invalid layer %1: %2" ).arg( layer->name(), reason ) );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe our code convention says that there can be only one ternary, not multiple ones nested.

@Withalion Withalion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ternary operators as mentioned by Tomas in 2 places

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.

App Crashes When Selecting Layer with Failed PostGIS Connection

3 participants