[price quotes] Pass short errors to gnc-quotes.

And wordier but not translated messages when STDERR is a tty.
This commit is contained in:
John Ralls 2022-10-13 17:57:11 -07:00
parent 88d658fef0
commit fe9b23ff2b

View File

@ -86,18 +86,26 @@ sub check_modules {
return unless @missing; return unless @missing;
print STDERR "\n"; # Test for STDERR being a tty and output a detailed message if it is
print STDERR "You need to install the following Perl modules:\n"; # and a short message if it isn't; in the latter case we're probably
foreach my $mod (@missing) { # being called from GnuCash and it will emit its own localized error.
print STDERR " ".$mod."\n"; if (-t STDERR)
{
print STDERR "\n";
print STDERR "You need to install the following Perl modules:\n";
foreach my $mod (@missing) {
print STDERR " ".$mod."\n";
}
print STDERR "\n";
print STDERR "Please see https://wiki.gnucash.org/wiki/Online_Quotes#Finance::Quote for detailed corrective action.\n";
print "missing-lib\n";
}
else
{
print STDERR "missing_modules ", join(" ", @missing), "\n";
} }
print STDERR "\n";
print STDERR "Use your system's package manager to install them,\n";
print STDERR "or run 'gnc-fq-update' as root.\n";
print "missing-lib\n";
exit 1; exit 1;
} }
@ -112,13 +120,17 @@ sub print_version {
} }
sub print_usage { sub print_usage {
print STDERR if (-t STDERR)
"Usage: {
my $message = << 'END';
Usage:
Check proper installation and version: Check proper installation and version:
finance-quote-wrapper -v finance-quote-wrapper -v
Fetch quotes (input should be passed as JSON via stdin): Fetch quotes (input should be passed as JSON via stdin):
finance-quote-wrapper -f finance-quote-wrapper -f
"; END
print STDERR $message;
}
} }
sub sanitize_hash { sub sanitize_hash {
@ -209,17 +221,28 @@ JSON::Parse->import(qw(valid_json parse_json));
my $json_input = do { local $/; <STDIN> }; my $json_input = do { local $/; <STDIN> };
if (!valid_json($json_input)) { if (!valid_json($json_input)) {
print STDERR "Could not parse input as valid JSON.\n"; if (-t STDERR)
print STDERR "Received input:\n$json_input\n"; {
print STDERR "Could not parse input as valid JSON.\n";
print STDERR "Received input:\n$json_input\n";
}
else
{
print STDERR "invalid_json\n";
}
exit 1; exit 1;
} }
my $requests = parse_json ($json_input); my $requests = parse_json ($json_input);
my $defaultcurrency = $$requests{'defaultcurrency'}; my $defaultcurrency = $$requests{'defaultcurrency'};
# This shouldn't be possible if we're called from GnuCash, so only warn in interactive use.
if (!$defaultcurrency) { if (!$defaultcurrency) {
$defaultcurrency = "USD"; $defaultcurrency = "USD";
print STDERR "Warning: no default currency was specified, assuming 'USD'\n"; if (-t STDERR)
{
print STDERR "Warning: no default currency was specified, assuming 'USD'\n";
}
} }
# Create a stockquote object. # Create a stockquote object.