Can i suppress error message from fetch.pm in Perl

前端 未结 2 860
轻奢々
轻奢々 2021-01-23 16:49

When using Fetch to download a url from Teamcity I get a Fetch failed! error. But the download of the file actually works.

They have recently changed permissions of our

相关标签:
2条回答
  • 2021-01-23 16:53

    It seems that the problem is a warning (message) being printed to STDERR. Apparently you are not getting a die or the program would exit. You can control the process of printing the message by setting the $SIG{__WARN__} hook, best localized in a block.

    my $where;
    
    FETCH: {
    
        local $SIG{__WARN__} = sub { 
            print "WARN: @_";        # or whatever appropriate
        };
    
        $where = $ff->fetch   ( to => "$DOWNLOAD_LOCATION" );    
    };
    

    or

    my $where = do { 
        local $SIG{__WARN__} = sub { print "WARN: @_" };
        $ff->fetch;
    };
    

    The signal's disposition – to print to STDERR – is restored outside of the block, which is what local provides. See this in perlsub, in particular text right after "Synopsis". You can also do that manually by saying $SIG{__WARN__} = 'DEFAULT'; once you are done.

    See warn

    No message is printed if there is a $SIG{__WARN__} handler installed. It is the handler's responsibility to deal with the message as it sees fit (like, for instance, converting it into a die).

    Also see %SIG entry in perlvar

    The routine indicated by $SIG{__WARN__} is called when a warning message is about to be printed. The warning message is passed as the first argument. The presence of a __WARN__ hook causes the ordinary printing of warnings to STDERR to be suppressed.


    While deciding what to call an "error" and what a "warning" may be a bit arbitrary, it appears clear that your program only emits a message to STDERR and continues. Then the above should suffice.

    If you were being hit by a die then you could wrap the code in eval.

    0 讨论(0)
  • 2021-01-23 17:04

    As the documentation explains, just set

    $File::Fetch::WARN = 0;
    

    to suppress warnings.

    0 讨论(0)
提交回复
热议问题