Skip to content

Commit

Permalink
Improve an error message to hint about one solution to charset issues
Browse files Browse the repository at this point in the history
This will hopefully hint the users about how to avoid bugs such as Debian' #1072643
  • Loading branch information
mquinson committed Jun 11, 2024
1 parent c75a90d commit 0717616
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions lib/Locale/Po4a/TransTractor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,14 @@ sub read() {
my $error = $@;
if ( length($error) ) {
chomp $error;
die wrap_msg( dgettext( "po4a", "Malformed encoding while reading from file %s with charset %s: %s" ),
$filename, $charset, $error );
die wrap_msg(
dgettext(
"po4a",
"Malformed encoding while reading from file %s with charset %s: %s\nIf %s is not the expected charset, you need to configure the right one with with --master-charset or other similar flags."
),
$filename,
$charset, $error, $charset
);
}

# Croak if we need to
Expand Down Expand Up @@ -548,11 +554,23 @@ sub write {
binmode STDERR, ':encoding(UTF-8)';
my $char = chr( hex($1) );
die wrap_msg(
dgettext( "po4a", "Malformed encoding while writing char '%s' to file %s with charset %s: %s" ),
$char, $filename, $charset, $error );
dgettext(
"po4a",
"Malformed encoding while writing char '%s' to file %s with charset %s: %s\nIf %s is not the expected charset, you need to configure the right one with with --localized-charset or other similar flags."
),
$char,
$filename,
$charset, $error, $charset
);
} else {
die wrap_msg( dgettext( "po4a", "Malformed encoding while writing to file %s with charset %s: %s" ),
$filename, $charset, $error );
die wrap_msg(
dgettext(
"po4a",
"Malformed encoding while writing to file %s with charset %s: %s\nIf %s is not the expected charset, you need to configure the right one with with --localized-charset or other similar flags."
),
$filename,
$charset, $error, $charset
);
}
};

Expand Down Expand Up @@ -651,8 +669,14 @@ sub addendum_parse {
} or do {
my $error = $@ || 'Unknown failure';
chomp $error;
die wrap_msg( dgettext( "po4a", "Malformed encoding while reading from file %s with charset %s: %s" ),
$filename, $charset, $error );
die wrap_msg(
dgettext(
"po4a",
"Malformed encoding while reading from file %s with charset %s: %s\nIf %s is not the expected charset, you need to configure the right one with with --master-charset or other similar flags."
),
$filename,
$charset, $error, $charset
);
};

unless ( $header =~ s/PO4A-HEADER://i ) {
Expand Down Expand Up @@ -723,8 +747,14 @@ sub addendum_parse {
my $error = $@;
if ( length($error) ) {
chomp $error;
die wrap_msg( dgettext( "po4a", "Malformed encoding while reading from file %s with charset %s: %s" ),
$filename, $charset, $error );
die wrap_msg(
dgettext(
"po4a",
"Malformed encoding while reading from file %s with charset %s: %s\nIf %s is not the expected charset, you need to configure the right one with with --master-charset or other similar flags."
),
$filename,
$charset, $error, $charset
);
}
close INS;

Expand Down

0 comments on commit 0717616

Please sign in to comment.