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

Improved error when proj_create doesn't recognize definition #2529

Closed
frewsxcv opened this issue Feb 12, 2021 · 8 comments
Closed

Improved error when proj_create doesn't recognize definition #2529

frewsxcv opened this issue Feb 12, 2021 · 8 comments

Comments

@frewsxcv
Copy link

frewsxcv commented Feb 12, 2021

#include <proj.h>
#include <stdio.h>

int main() {
    PJ* pj_point = proj_create(0, "a b c d e f g h i j");
    if (pj_point) {
        printf("proj_create succeeded\n");
    } else {
        int errno = proj_context_errno(0);
        const char* error_string = proj_errno_string(errno);
        printf("%s\n", error_string);
    }
    return 0;
}

If PROJ doesn't recognize the definition provided to proj_create, the error that gets returned is generic error of unknown origin which makes it hard for users finding out what went wrong

@frewsxcv
Copy link
Author

frewsxcv commented Feb 12, 2021

One other thing to add is the proj_create documentation recommends retrieving the errno if the call fails:

If creation of the transformation object fails, the function returns 0 and the PROJ error number is updated. The error number can be read with proj_errno() or proj_context_errno().

@stale
Copy link

stale bot commented Jun 9, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 9, 2021
@frewsxcv
Copy link
Author

Does anyone know where the relevant code is? I might have capacity to make this change

@stale stale bot removed the wontfix label Jun 22, 2021
@direvus
Copy link
Contributor

direvus commented Nov 4, 2021

Hi @frewsxcv, running your sample code I get:

proj_create: unrecognized format / unknown name
Unknown error (code 4096)

Maybe this has been improved since you raised the issue?

I think "proj_create: unrecognized format" is clear enough to point users in the right direction. Is there anything about it you'd want to change?

@frewsxcv frewsxcv closed this as completed Nov 6, 2021
@frewsxcv
Copy link
Author

frewsxcv commented Nov 6, 2021

Thanks for the update!

@frewsxcv frewsxcv reopened this Jan 30, 2022
@frewsxcv
Copy link
Author

Hi @frewsxcv, running your sample code I get:

proj_create: unrecognized format / unknown name
Unknown error (code 4096)

Maybe this has been improved since you raised the issue?

I think "proj_create: unrecognized format" is clear enough to point users in the right direction. Is there anything about it you'd want to change?

The proj_create: unrecognized format is getting logged by the logger, from what I understand. Unknown error (code 4096) is the actual string that gets returned, which is what would get displayed to the user, which isn't so helpful.

direvus pushed a commit to direvus/PROJ that referenced this issue Feb 4, 2022
If proj_create() catches a ParsingException, set the error code to
PROJ_ERR_INVALID_OP_WRONG_SYNTAX instead of the generic PROJ_ERR_OTHER.

Ref OSGeo#2529
@direvus
Copy link
Contributor

direvus commented Feb 4, 2022

OK @frewsxcv, thanks, I think I understand the problem better now.

I think this works better if we have proj_create set the error code to INVALID_OP_WRONG_SYNTAX ("Invalid PROJ string syntax") when the underlying function throws a ParsingException. Does that work for you?

With this change, running your test program outputs as follows:

proj_create: unrecognized format / unknown name
Invalid PROJ string syntax

@frewsxcv
Copy link
Author

frewsxcv commented Feb 4, 2022

@direvus Yep, that's perfect. Thanks!

direvus pushed a commit to direvus/PROJ that referenced this issue Feb 4, 2022
If proj_create() catches a ParsingException, and the error code hasn't
otherwise been set internally, set the error code to
PROJ_ERR_INVALID_OP_WRONG_SYNTAX instead of allowing it to default to
the generic PROJ_ERR_OTHER.

Ref OSGeo#2529
@rouault rouault closed this as completed Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants