Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5372c2c

Browse files
committed
Improve error detection/reporting in Catalog.pm and genbki.pl.
Clean up error messages relating to mistakes in .dat files: make sure theyprovide the .dat file name and line number, not the place in the Perlscript that's reporting the problem. Adopt more uniform message phrasing,too.Make genbki.pl spit up on unrecognized field names in the input hashes.Previously, it just silently ignored such fields, which could make amisspelled field name into a very hard-to-decipher problem. (This is ingenbki.pl, *not* Catalog.pm, because we don't want reformat_dat_file.pl tocomplain about unrecognized fields. We'd rather it silently dropped them,to facilitate removing unwanted fields after a reorganization.)
1 parent1dec820 commit5372c2c

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

‎src/backend/catalog/Catalog.pm

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ sub ParseData
226226

227227
open(my$ifd,'<',$input_file) ||die"$input_file:$!";
228228
$input_file =~/(\w+)\.dat$/
229-
ordie"Input file needs to be a .dat file.\n";
229+
ordie"Input file$input_fileneeds to be a .dat file.\n";
230230
my$catname =$1;
231231
my$data = [];
232232

@@ -245,7 +245,9 @@ sub ParseData
245245

246246
# Quick hack to detect when we have a full hash ref to
247247
# parse. We can't just use a regex because of values in
248-
# pg_aggregate and pg_proc like '{0,0}'.
248+
# pg_aggregate and pg_proc like '{0,0}'. This will need
249+
# work if we ever need to allow unbalanced braces within
250+
# a field value.
249251
my$lcnt =tr/{//;
250252
my$rcnt =tr/}//;
251253

@@ -254,29 +256,30 @@ sub ParseData
254256
eval'$hash_ref =' .$_;
255257
if (!ref$hash_ref)
256258
{
257-
die"Errorparsing$_\n$!";
259+
die"$input_file: errorparsingline$.:\n$_\n";
258260
}
259261

262+
# Annotate each hash with the source line number.
263+
$hash_ref->{line_number} =$.;
264+
260265
# Expand tuples to their full representation.
261266
AddDefaultValues($hash_ref,$schema,$catname);
262267
}
263268
else
264269
{
265270
my$next_line = <$ifd>;
266-
die"$input_file: ends within Perl hash\n"
271+
die"$input_file:fileends within Perl hash\n"
267272
if !defined$next_line;
268273
$_ .=$next_line;
269274
redo;
270275
}
271276
}
272277

273-
# If we found a hash reference, keep it
274-
# and annotate the line number.
278+
# If we found a hash reference, keep it.
275279
# Only keep non-data strings if we
276280
# are told to preserve formatting.
277281
if (defined$hash_ref)
278282
{
279-
$hash_ref->{line_number} =$.;
280283
push@$data,$hash_ref;
281284
}
282285
elsif ($preserve_formatting)
@@ -324,14 +327,8 @@ sub AddDefaultValues
324327

325328
if (@missing_fields)
326329
{
327-
my$msg ="Failed to form full tuple for$catname\n";
328-
$msg .="Missing values for:" .join(',',@missing_fields);
329-
$msg .="\nOther values for row:\n";
330-
while (my($key,$value) =each%$row)
331-
{
332-
$msg .="$key =>$value,";
333-
}
334-
die$msg;
330+
diesprintf"missing values for field(s)%s in%s.dat line%s\n",
331+
join(',',@missing_fields),$catname,$row->{line_number};
335332
}
336333
}
337334

‎src/backend/catalog/genbki.pl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,17 @@
280280

281281
print$bki"\n (\n";
282282
my$schema =$catalog->{columns};
283+
my%attnames;
283284
my$attnum = 0;
284285
foreachmy$column (@$schema)
285286
{
286287
$attnum++;
287288
my$attname =$column->{name};
288289
my$atttype =$column->{type};
289290

291+
# Build hash of column names for use later
292+
$attnames{$attname} = 1;
293+
290294
# Emit column definitions
291295
if (!$first)
292296
{
@@ -338,6 +342,16 @@
338342
{
339343
my%bki_values =%$row;
340344

345+
# Complain about unrecognized keys; they are presumably misspelled
346+
foreachmy$key (keys%bki_values)
347+
{
348+
nextif$keyeq"oid" ||$keyeq"oid_symbol" ||$keyeq"descr"
349+
||$keyeq"line_number";
350+
diesprintf"unrecognized field name\"%s\" in%s.dat line%s\n",
351+
$key,$catname,$bki_values{line_number}
352+
if (!exists($attnames{$key}));
353+
}
354+
341355
# Perform required substitutions on fields
342356
foreachmy$column (@$schema)
343357
{
@@ -724,6 +738,9 @@ sub morph_row_for_schemapg
724738
# Perform OID lookups on an array of OID names.
725739
# If we don't have a unique value to substitute, warn and
726740
# leave the entry unchanged.
741+
# (A warning seems sufficient because the bootstrap backend will reject
742+
# non-numeric values anyway. So we might as well detect multiple problems
743+
# within this genbki.pl run.)
727744
sublookup_oids
728745
{
729746
my ($lookup,$catname,$bki_values,@lookupnames) =@_;
@@ -739,7 +756,7 @@ sub lookup_oids
739756
else
740757
{
741758
push@lookupoids,$lookupname;
742-
warnsprintf"unresolved OID reference\"%s\" in%s.dat line%s",
759+
warnsprintf"unresolved OID reference\"%s\" in%s.dat line%s\n",
743760
$lookupname,$catname,$bki_values->{line_number}
744761
if$lookupnamene'-'and$lookupnamene'0';
745762
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp