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

raise an error on warnings in tests #812

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

mockdeep
Copy link
Member

No description provided.

@mockdeep
Copy link
Member Author

This is an experiment to see what will happen.

@mockdeep mockdeep self-assigned this Sep 29, 2019
@mockdeep mockdeep force-pushed the rf-stderr_raise branch 2 times, most recently from 9ae2a52 to 77d1830 Compare October 6, 2019 01:38
@mockdeep
Copy link
Member Author

mockdeep commented Oct 6, 2019

@dlemstra I've been able to fix most of the warnings on this branch, but there are still a couple that I'm not sure about. Do you have any idea on the remaining ones?

@dlemstra
Copy link
Member

dlemstra commented Oct 6, 2019

Just pushed some extra changes to fix the errors. Now wondering if we should not make a setting for"treat warning as errors" in the code (instead of overriding stderr.write) so our users can also do this? The following 'hack' could make this possible:

void
rm_warning_handler(const ExceptionType severity, const char *reason, const char *description)
{
    if (getenv("RMAGICK_WARNING_IS_ERROR"))
    {
        rm_error_handler(severity, reason, description);
        return;
    }

    rb_warning("RMagick: %s%s%s",
        GetLocaleExceptionMessage(severity, reason),
        description ? ": " : "",
        description ? GetLocaleExceptionMessage(severity, description) : "");
}

Or we could introduce a new method that sets a variable that is used here. Your thoughts?

@mockdeep
Copy link
Member Author

mockdeep commented Oct 6, 2019

Nice! Thanks for looking into it. I wonder, would it be reasonable to just throw an error in this cases rather than allowing them to configure it? If they're using the library wrong, I guess my preference would be to fail fast and loud. Warnings have a way of slipping through the cracks. I suppose we could also have something like your suggestion as a transitional tool:

  • 4.x -> add ability to toggle on
  • 5.x -> turn it on by default
  • 6.x -> remove the option

@dlemstra
Copy link
Member

dlemstra commented Oct 6, 2019

Maybe it would be better to allow a user to set warning handling to one of the following values: Quiet, Warnning or Error? I don't think it will be a good idea to force a user to treat a warning as error. Some places might raise a warning where the user does not care about.

@mockdeep
Copy link
Member Author

mockdeep commented Oct 6, 2019

Yeah, I guess it depends on the severity of it. In general, if they're using the library wrong I'd prefer an error. If it's just something that should work but might produce results that are a little odd, maybe a warning makes more sense. Even in those cases, though, I might still throw an error and push them to be more explicit about what they want. If they don't care, they can always rescue the error in their code. It might be more productive to discuss these on a case-by-case basis, though.

@dlemstra
Copy link
Member

dlemstra commented Oct 6, 2019

I am just a bit worried that this will break existing code of a user. Maybe we could still allow the 3 choices and set the default to raise an error?

@mockdeep
Copy link
Member Author

mockdeep commented Oct 6, 2019

Yeah, that makes sense. I think it would be important to have a transition plan. Rather than immediately starting to throw an error by default, we probably want to default it to warning like it does now, and allow a user to configure it. If we want to make throwing an error the default, we can add a deprecation warning in the 4.x version and in 5.0 we can make it the new default.

Base automatically changed from master to main January 22, 2021 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants