Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix QgsCsException messages #59484

Merged
merged 7 commits into from
Nov 20, 2024
Merged

Fix QgsCsException messages #59484

merged 7 commits into from
Nov 20, 2024

Conversation

nyalldawson
Copy link
Collaborator

Heh... for the longest time I thought the useless forward transform of (inf, inf) exceptions messages contained within QgsCsException were just proj not giving very useful error messages... but it turns out our QgsCsException message generation logic was completely wonky and generating nonsense messages.

Let's fix that!

Instead of:

QgsCsException: forward transform of
(inf, inf)
Error: Fallback transform failed

we now get much more useful exceptions, like:

QgsCsException: Forward transform (EPSG:4326 to EPSG:3857) of (-7603859.000000, -7324441.000000) Error: Invalid coordinate

We were incorrectly showing the "transformed" coordinate result
in the exception message, which usually ended up inf, inf after
the transform fails. This lead to a useless 'forward transform of
(inf, inf)' message in the exception, which was misleading
as it looks like we were trying to transform a (inf, inf) point.

Now we get the (useful!) actual coordinate we were trying
to transform in the exception message.
The old code mistakenly assumed that proj error codes were all
values < 0, which they haven't been since proj 8.0

This meant all QgsCsExceptions were incorrectly including
"Error: Fallback transform failed", instead of the actual
error message from proj.

Now we get eg "Forward transform of (-7603859.000000, -7324441.000000)
Error: Invalid coordinate", which makes much more sense
Eg:

    Forward transform (EPSG:4326 to EPSG:3857) of
    (-7603859.000000, -7324441.000000) Error: Invalid coordinate
@nyalldawson
Copy link
Collaborator Author

@rouault One thing I can't work out how to fix is the hardcoded -61 error number here: https://github.com/qgis/QGIS/blob/master/src/core/proj/qgscoordinatetransform_p.cpp#L335 .

I gather that would have been changed by OSGeo/PROJ#2487, but I'm not 100% sure what the corresponding constant should be. Is it PROJ_ERR_COORD_TRANSFM_NO_OPERATION ?

Copy link

github-actions bot commented Nov 18, 2024

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit 5733e3d)

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit 5733e3d)

@rouault
Copy link
Contributor

rouault commented Nov 18, 2024

I believe if ( errNo && errNo != -61 ) should just be simplified as `if ( errNo )`` . The PROJ < 8 "-61" code was meant for a generic / unknown error.

@nyalldawson
Copy link
Collaborator Author

@rouault ok, removed

@troopa81 troopa81 merged commit 458185a into qgis:master Nov 20, 2024
31 checks passed
@qgis-bot
Copy link
Collaborator

The backport to queued_ltr_backports failed:

The process '/usr/bin/git' failed with exit code 1
stderr
error: could not apply 9b69cafa16b... Include crs IDs in QgsCsException message
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config advice.mergeConflict false"

stdout
Auto-merging src/core/proj/qgscoordinatetransform.cpp
[backport-59484-to-queued_ltr_backports 1ffac8d399f] Show actual original coordinate in QgsCsException message
 Author: Nyall Dawson <nyall.dawson@gmail.com>
 Date: Tue Nov 19 08:44:41 2024 +1100
 1 file changed, 1 insertion(+), 1 deletion(-)
Auto-merging src/core/proj/qgscoordinatetransform.cpp
[backport-59484-to-queued_ltr_backports a66be2dd168] Don't needlessly split QgsCsException message to multilines when we don't need to
 Author: Nyall Dawson <nyall.dawson@gmail.com>
 Date: Tue Nov 19 08:47:26 2024 +1100
 1 file changed, 5 insertions(+), 5 deletions(-)
Auto-merging src/core/proj/qgscoordinatetransform.cpp
[backport-59484-to-queued_ltr_backports 7cdca6ea686] Show actual proj error message in QgsCsException
 Author: Nyall Dawson <nyall.dawson@gmail.com>
 Date: Tue Nov 19 08:48:04 2024 +1100
 1 file changed, 5 insertions(+), 3 deletions(-)
Auto-merging src/core/proj/qgscoordinatereferencesystem.cpp
Auto-merging src/core/proj/qgscoordinatetransform.cpp
Auto-merging src/core/proj/qgscoordinatetransform_p.cpp
[backport-59484-to-queued_ltr_backports 9b5d4ed138f] Avoid deprecated proj_errno_string on proj >= 8.0
 Author: Nyall Dawson <nyall.dawson@gmail.com>
 Date: Tue Nov 19 08:54:54 2024 +1100
 3 files changed, 20 insertions(+), 1 deletion(-)
Auto-merging src/core/proj/qgscoordinatetransform.cpp
Auto-merging tests/src/python/test_qgscoordinatetransform.py
CONFLICT (content): Merge conflict in tests/src/python/test_qgscoordinatetransform.py

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-queued_ltr_backports queued_ltr_backports
# Navigate to the new working tree
cd .worktrees/backport-queued_ltr_backports
# Create a new branch
git switch --create backport-59484-to-queued_ltr_backports
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick c8d25f6ceff4450687c5ad29d09e3686dd3f59d4,276cbec30e9a44ce383d37fbbb6e8837b95483ee,00c7268020aab2516efa49cbba43566b80cc9c82,16de21a78ec15fa3c9f2add0829a81c57874b33c,9b69cafa16b775611515c45762ab378c398b2840,b682d36b06f20065994b0707f1306a6c295b8790,5733e3d3f2cd60942356f2a6f586fdbcf3eaea19
# Push it to GitHub
git push --set-upstream origin backport-59484-to-queued_ltr_backports
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-queued_ltr_backports

Then, create a pull request where the base branch is queued_ltr_backports and the compare/head branch is backport-59484-to-queued_ltr_backports.

@qgis-bot qgis-bot added the failed backport The automated backport attempt failed, needs a manual backport label Nov 20, 2024
@nyalldawson nyalldawson deleted the cs_error branch November 21, 2024 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport queued_ltr_backports Queued Backports backport release-3_40 failed backport The automated backport attempt failed, needs a manual backport
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants