summaryrefslogtreecommitdiff
path: root/doc/TODO.detail/error
blob: 7daf315463cff0f1c8a91fd81896be735e8bd50e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
From pgsql-hackers-owner+M16120=candle.pha.pa.us=pgman@postgresql.org Fri Nov 30 12:14:19 2001
Return-path: <pgsql-hackers-owner+M16120=candle.pha.pa.us=pgman@postgresql.org>
Received: from rs.postgresql.org (server1.pgsql.org [64.39.15.238] (may be forged))
	by candle.pha.pa.us (8.11.6/8.10.1) with ESMTP id fAUIEIR21802
	for <pgman@candle.pha.pa.us>; Fri, 30 Nov 2001 13:14:18 -0500 (EST)
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by rs.postgresql.org (8.11.6/8.11.6) with ESMTP id fAUI6ER13094
	for <pgman@candle.pha.pa.us>; Fri, 30 Nov 2001 12:11:00 -0600 (CST)
	(envelope-from pgsql-hackers-owner+M16120=candle.pha.pa.us=pgman@postgresql.org)
Received: from moutvdom01.kundenserver.de (moutvdom01.kundenserver.de [195.20.224.200])
	by postgresql.org (8.11.3/8.11.4) with ESMTP id fAUI58m98870
	for <pgsql-hackers@postgresql.org>; Fri, 30 Nov 2001 13:05:08 -0500 (EST)
	(envelope-from peter_e@gmx.net)
Received: from [195.20.224.208] (helo=mrvdom01.schlund.de)
	by moutvdom01.kundenserver.de with esmtp (Exim 2.12 #2)
	id 169s27-00049P-00
	for pgsql-hackers@postgresql.org; Fri, 30 Nov 2001 19:05:07 +0100
Received: from p3e9e6fa2.dip0.t-ipconnect.de ([62.158.111.162])
	by mrvdom01.schlund.de with esmtp (Exim 2.12 #2)
	id 169s21-0001UP-00
	for pgsql-hackers@postgresql.org; Fri, 30 Nov 2001 19:05:03 +0100
Date: Fri, 30 Nov 2001 19:12:16 +0100 (CET)
From: Peter Eisentraut <peter_e@gmx.net>
X-Sender: <peter@peter.localdomain>
To: PostgreSQL Development <pgsql-hackers@postgresql.org>
Subject: [HACKERS] Backend error message style issues
Message-ID: <Pine.LNX.4.30.0111292302020.609-100000@peter.localdomain>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Precedence: bulk
Sender: pgsql-hackers-owner@postgresql.org
Status: ORr

Now that we've gone through nearly one development cycle with national
language support, I'd like to bring up a number of issues concerning the
style of the backend error messages that make life difficult, but probably
not only for the translators but for users as well.  Not all of these are
strictly translation issues, but the message catalogs make for a good
overview of what's going on.

I hope we can work through all of these during the next development
period.

Prefixing messages with command names
-------------------------------------

For instance,

| CREATE DATABASE: permission denied

This "command: message" style is typical for command-line programs and
it's pretty useful there if you run many commands in a pipe.  The same
usefulness could probably be derived if you run many SQL commands in a
function.  (Just "permission denied" would be very confusing there!)

If we want to use that style we should make it consistent and we should
automate it.  Via the "command tag" mechanism we already know what command
we're executing, so we can automatically prefix all messages that way.  It
could even be switched off by the user if it's deemed annoying.


Prefixing messages with function names
--------------------------------------

The function names obviously have no meaning to the user.  It is claimed
that they allow a developer to locate the place the error was raised
faster, but that's only half the truth.  Firstly, this whole thing doesn't
work if the displayed name of the function was actually passed in from
elsewhere.  Then it takes you three times longer to locate the source
because you *think* you know where it was but it's not there.  Secondly,
a developer doesn't have the need to locate every error.  For instance,

| ExecAppend: rejected due to CHECK constraint foo

There's no need to debug anything there, it's a perfectly normal use
situation.

I think the key here is to distinguish error messages that are perfectly
normal user-level events from messages which really represent an "assert
failure, but continue gracefully", such as

| initGISTstate: numberOfAttributes %d > %d

The latter could better be written something like

| BETTER_BE_TRUE(index->rd_att->natts > INDEX_MAX_KEYS);

we could lead to an error message in the style of an assert failure,
including the expression in question and file and line information (and
bug reporting suggestions).  This way the developer doesn't have to write
any message text at all but still gets much better information to locate
the source.  (E.g., note that the tested variable isn't even called
"numberOfAttributes".)

The exact API could be tuned to include some other information such as an
informal message, but I think something along these lines needs to be
worked out.


Quoting
-------

Which is better:

function '%s' not found
function "%s" not found
function %s not found

I think two kinds of quotes is looking messy.  Personal suggestion:
double quotes.


Capitalization and punctuation
------------------------------

Which one?

ERROR:  Permission denied.
ERROR:  Permission denied
ERROR:  permission denied

I have personally used the GNU-recommended way which is the third, mostly
just because it is *some* standardized way.  I don't have a strong feeling
about the initial capitalization, but I'm against the periods except when
the message is really a sentence and it contains some other punctuation
(commas, etc.) or the message consists of more than one sentence.


Grammatical structure and choice of words
-----------------------------------------

There are many others besides the above choices:

ERROR: Permission was denied.
ERROR: You don't have permission to do <task>.
ERROR: Permission to do <task> was denied.
ERROR: <task>: Permission denied

In other cases there's a sea of possibilities:

couldn't find THING
can't find THING
THING wasn't found
unable to locate THING
lookup of THING failed
THING doesn't exist

Strictly speaking, there are at least four different meanings among those
six messages, yet they're used mostly randomly.

There are a number of things to think about here: active vs passive, can
vs could, complete sentence vs telegram style, use of colons, addressing
the user with "you [cannot...]".

And please let's not have the program talk in the "I"-form ("I have rolled
back the current transaction ...").



More esoteric discussions are also possible, but I'm going to postpone
those. ;-)  However, I think it's worth working on this and perhaps
putting together a "manual of style" that applies to all parts of
PostgreSQL.  This would significantly improve the overall perceived
quality.  Some projects like KDE, GNU, and GCC have teams that discuss
these kinds of things and it's definitely showing.

-- 
Peter Eisentraut   peter_e@gmx.net


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

From pgsql-hackers-owner+M16128=candle.pha.pa.us=pgman@postgresql.org Fri Nov 30 13:39:41 2001
Return-path: <pgsql-hackers-owner+M16128=candle.pha.pa.us=pgman@postgresql.org>
Received: from rs.postgresql.org (server1.pgsql.org [64.39.15.238] (may be forged))
	by candle.pha.pa.us (8.11.6/8.10.1) with ESMTP id fAUJdfR29066
	for <pgman@candle.pha.pa.us>; Fri, 30 Nov 2001 14:39:41 -0500 (EST)
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by rs.postgresql.org (8.11.6/8.11.6) with ESMTP id fAUJXkR15701
	for <pgman@candle.pha.pa.us>; Fri, 30 Nov 2001 13:36:17 -0600 (CST)
	(envelope-from pgsql-hackers-owner+M16128=candle.pha.pa.us=pgman@postgresql.org)
Received: from corvette.mascari.com (dhcp065-024-158-068.columbus.rr.com [65.24.158.68])
	by postgresql.org (8.11.3/8.11.4) with ESMTP id fAUJMnm01940
	for <pgsql-hackers@postgresql.org>; Fri, 30 Nov 2001 14:22:49 -0500 (EST)
	(envelope-from mascarm@mascari.com)
Received: from mascari.com (ferrari.mascari.com [192.168.2.1])
	by corvette.mascari.com (8.9.3/8.9.3) with ESMTP id OAA20637;
	Fri, 30 Nov 2001 14:16:52 -0500
Message-ID: <3C07DBAD.A9735975@mascari.com>
Date: Fri, 30 Nov 2001 14:19:09 -0500
From: Mike Mascari <mascarm@mascari.com>
Organization: Mascari Development Inc.
X-Mailer: Mozilla 4.77 [en] (WinNT; U)
X-Accept-Language: en
MIME-Version: 1.0
To: Peter Eisentraut <peter_e@gmx.net>
cc: PostgreSQL Development <pgsql-hackers@postgresql.org>
Subject: Re: [HACKERS] Backend error message style issues
References: <Pine.LNX.4.30.0111292302020.609-100000@peter.localdomain>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Precedence: bulk
Sender: pgsql-hackers-owner@postgresql.org
Status: OR

Peter Eisentraut wrote:
> 
> Now that we've gone through nearly one development cycle with national
> language support, I'd like to bring up a number of issues concerning the
> style of the backend error messages that make life difficult, but probably
> not only for the translators but for users as well.  Not all of these are
> strictly translation issues, but the message catalogs make for a good
> overview of what's going on.

For what its worth, Oracle 8 ships with an error.txt file which
dictates the message standards to which their products comply.
Roughly:

Size Of Message:
---------------

Cannot exceed 76 characters, even when embedded format specifiers
are apart of the message. Only 
start-up and system-dependent messages can exceed 76 characters.

Simple Language:
---------------

Use non-cryptic messages and overly technical language.

Upper vs. Lowercase:
-------------------

Use uppercase for commands and keywords, lowercase for message
wording, including the first letter (which agrees with your use,
Peter).

Commands, Keywords, Parameter Values:
------------------------------------

When possible, give the command, keyword and parameters used in the
message. 

BAD: The relation could not be created
GOOD: CREATE TABLE failed for table "foo" because the disk is full

Period:
------

Do not end messages with a period (also agrees with your
conclusion).

Numbers:
-------

Don't enclose numbers with special characters. For example:

BAD: rows returned by subquery (3) exceeded limit (1)
GOOD: the subquery returned 3 rows exceeding the 1 row limit

Quotes:
------

Don't use single or double quotes to emphasize a text variable or
command

Single Quotes:
-------------

Never use them.

Double Quotes:
-------------

Always and only use them to identify database objects. 

BAD: Unable to drop table employees
GOOD: DROP TABLE of "employees" failed due to referential integrity
constraints

Ellipses:
--------

Don't use them. 

BAD: Unable to drop column mascarm.employees.salary
GOOD: ALTER TABLE was unable to drop the column "salary" table
"employees" schema "mascarm"

Parentheses:
-----------

Always and only use parentheses for constraint names

BAD: not null constraint ri_employees violated
GOOD: not null constraint (ri_employees) violated

Brackets:
--------

Always and only used for program arguments

Grammar:
-------

Use complete sentences whenever possible without the trailing
period. Don't use multiple sentences. Use the active voice. Don't
use an aggressive tone.

Style:
-----

Make positive suggestions. Explain what is invalid and what is
valid.

Example:

BAD: file name invalid
BETTER: COPY failed because the file name was too long

Routine names:
-------------

Do not use routine names in messages. Again, agrees with you, Peter.

FWIW, 

Mike Mascari
mascarm@mascari.com

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

From pgsql-hackers-owner+M16130=candle.pha.pa.us=pgman@postgresql.org Fri Nov 30 14:09:48 2001
Return-path: <pgsql-hackers-owner+M16130=candle.pha.pa.us=pgman@postgresql.org>
Received: from rs.postgresql.org (server1.pgsql.org [64.39.15.238] (may be forged))
	by candle.pha.pa.us (8.11.6/8.10.1) with ESMTP id fAUK9lR02095
	for <pgman@candle.pha.pa.us>; Fri, 30 Nov 2001 15:09:48 -0500 (EST)
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by rs.postgresql.org (8.11.6/8.11.6) with ESMTP id fAUK3MR16820
	for <pgman@candle.pha.pa.us>; Fri, 30 Nov 2001 14:05:48 -0600 (CST)
	(envelope-from pgsql-hackers-owner+M16130=candle.pha.pa.us=pgman@postgresql.org)
Received: from sss.pgh.pa.us ([192.204.191.242])
	by postgresql.org (8.11.3/8.11.4) with ESMTP id fAUJnLm02954
	for <pgsql-hackers@postgresql.org>; Fri, 30 Nov 2001 14:49:21 -0500 (EST)
	(envelope-from tgl@sss.pgh.pa.us)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id fAUJnEi10307;
	Fri, 30 Nov 2001 14:49:14 -0500 (EST)
To: Peter Eisentraut <peter_e@gmx.net>
cc: PostgreSQL Development <pgsql-hackers@postgresql.org>
Subject: Re: [HACKERS] Backend error message style issues 
In-Reply-To: <Pine.LNX.4.30.0111292302020.609-100000@peter.localdomain> 
References: <Pine.LNX.4.30.0111292302020.609-100000@peter.localdomain>
Comments: In-reply-to Peter Eisentraut <peter_e@gmx.net>
	message dated "Fri, 30 Nov 2001 19:12:16 +0100"
Date: Fri, 30 Nov 2001 14:49:14 -0500
Message-ID: <10303.1007149754@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
Precedence: bulk
Sender: pgsql-hackers-owner@postgresql.org
Status: OR

Peter Eisentraut <peter_e@gmx.net> writes:
> I hope we can work through all of these during the next development
> period.

Too bad we didn't do it *before* doing a lot of translation work :-(.

Yes, I agree that a pass of rationalizing the error messages would be
useful.  Might want to think about that old bugaboo, error codes,
while we're at it.  Also the perennial complaint that "ERROR" and
"DEBUG" macros tend to conflict with other things.  As long as we're
going to touch many/all of the elog() calls, couldn't we try to clean
up all these issues?

> Which is better:

> function '%s' not found
> function "%s" not found
> function %s not found

Given that 'x' and "x" mean very different things in SQL, I think that
the first form is just plain wrong when an identifier is involved.
Unfortunately a lot of older code uses that style.  I've tried to use
double quotes in new messages, but have restrained myself from wholesale
changes of existing messages.

> More esoteric discussions are also possible, but I'm going to postpone
> those. ;-)  However, I think it's worth working on this and perhaps
> putting together a "manual of style" that applies to all parts of
> PostgreSQL.  This would significantly improve the overall perceived
> quality.

Sounds like a plan to me: put together a style guide first, and then
make a pass through the code to try to implement it.

			regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

From pgsql-hackers-owner+M25090@postgresql.org Wed Jul 17 14:27:47 2002
Return-path: <pgsql-hackers-owner+M25090@postgresql.org>
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by candle.pha.pa.us (8.11.6/8.10.1) with ESMTP id g6HIRke20336
	for <pgman@candle.pha.pa.us>; Wed, 17 Jul 2002 14:27:46 -0400 (EDT)
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by postgresql.org (Postfix) with SMTP
	id A5EC0475931; Wed, 17 Jul 2002 14:27:42 -0400 (EDT)
Received: from klamath.dyndns.org (CPE002078144ae0.cpe.net.cable.rogers.com [24.102.202.35])
	by postgresql.org (Postfix) with ESMTP id 8C8A74758F5
	for <pgsql-hackers@postgresql.org>; Wed, 17 Jul 2002 14:27:39 -0400 (EDT)
Received: by klamath.dyndns.org (Postfix, from userid 1000)
	id D98827015; Wed, 17 Jul 2002 14:27:39 -0400 (EDT)
Date: Wed, 17 Jul 2002 14:27:39 -0400
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: [HACKERS] error codes
Message-ID: <20020717182739.GB5542@klamath.dyndns.org>
Mail-Followup-To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.4i
From: nconway@klamath.dyndns.org (Neil Conway)
Precedence: bulk
Sender: pgsql-hackers-owner@postgresql.org
Status: ORr

I'd like to implement error codes. I think they would be pretty useful,
although there are a few difficulties in the implementation I'd like
to get some input on.

Should every elog() have an error code? I'm not sure -- there are many
elog() calls that will never been seen by the user, since the error
they represent will be caught before control reaches the elog (e.g.
parse errors, internal consistency checks, multiple elog(ERROR)
for the same user error, etc.) Perhaps for those error messages
that don't have numbers, we could just give them ERRNO_UNKNOWN or
a similar constant.

How should the backend code signal an error with an error number?
Perhaps we could report errors with error numbers via a separate
function, which would take the error number as its only param.
For example:

error(ERRNO_REF_INT_VIOLATION);

The problem here is that many errors will require more information
that that, in order for the client to handle them properly. For
example, how should a COPY indicate that an RI violation has
occured? Ideally, we'd like to allow the client application to
know that in line a, column b, the literal value 'c' was
not found in the referenced column d of the referenced table d.

How should the error number be sent to the client, and would this
require an FE/BE change? I think we can avoid that: including the
error number in the error message itself, make PQgetErrorMessage()
(and similar funcs) smart enough to remove the error number, and
add a separate function (such as PQgetErrorNumber() ) to report
the error number, if there is one.

On a related note, it would be nice to get a consistent style of
punctuation for elog() messages -- currently, some of them end
in a period (e.g. "Database xxx does not exist in the system
catalog."), while the majority do not. Which is better?

Also, I think it was Bruce who mentioned that it would be nice
to add function names, source files, and/or line numbers to error
messages, instead of the current inconsistent method of sometimes
specifying the function name in the elog() message. Would this
be a good idea? Should all errors include this information?

It would be relatively easy to replace elog() with a macro of
the form:

#define elog(...) real_elog(__FILE__, __LINE__, __VA_ARGS__)

And then adjust real_elog() to report that information as
appropriate.

Cheers,

Neil

-- 
Neil Conway <neilconway@rogers.com>
PGP Key ID: DB3C29FC

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

From pgsql-hackers-owner+M25094@postgresql.org Wed Jul 17 15:58:08 2002
Return-path: <pgsql-hackers-owner+M25094@postgresql.org>
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by candle.pha.pa.us (8.11.6/8.10.1) with ESMTP id g6HJw7e27032
	for <pgman@candle.pha.pa.us>; Wed, 17 Jul 2002 15:58:07 -0400 (EDT)
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by postgresql.org (Postfix) with SMTP
	id 73DA3475C3D; Wed, 17 Jul 2002 15:58:00 -0400 (EDT)
Received: from sss.pgh.pa.us (unknown [192.204.191.242])
	by postgresql.org (Postfix) with ESMTP id BDA71475D6F
	for <pgsql-hackers@postgresql.org>; Wed, 17 Jul 2002 15:57:56 -0400 (EDT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.12.5/8.12.5) with ESMTP id g6HJvuAl016463;
	Wed, 17 Jul 2002 15:57:56 -0400 (EDT)
To: nconway@klamath.dyndns.org (Neil Conway)
cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: Re: [HACKERS] error codes 
In-Reply-To: <20020717182739.GB5542@klamath.dyndns.org> 
References: <20020717182739.GB5542@klamath.dyndns.org>
Comments: In-reply-to nconway@klamath.dyndns.org (Neil Conway)
	message dated "Wed, 17 Jul 2002 14:27:39 -0400"
Date: Wed, 17 Jul 2002 15:57:56 -0400
Message-ID: <16462.1026935876@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
Precedence: bulk
Sender: pgsql-hackers-owner@postgresql.org
Status: OR

nconway@klamath.dyndns.org (Neil Conway) writes:
> Should every elog() have an error code?

I believe we decided that it'd be okay to use one or two codes defined
like "internal error", "corrupted data", etc for all the elogs that are
not-supposed-to-happen conditions.  What error codes are really for is
distinguishing different kinds of user mistakes, and so that's where
you need specificness.

> How should the backend code signal an error with an error number?

Please read some of the archived discussions about this.  All the points
you mention have been brought up before.

			regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

From pgsql-hackers-owner+M25095@postgresql.org Wed Jul 17 16:18:08 2002
Return-path: <pgsql-hackers-owner+M25095@postgresql.org>
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by candle.pha.pa.us (8.11.6/8.10.1) with ESMTP id g6HKI8e28852
	for <pgman@candle.pha.pa.us>; Wed, 17 Jul 2002 16:18:08 -0400 (EDT)
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by postgresql.org (Postfix) with SMTP
	id 68FAB475C69; Wed, 17 Jul 2002 16:18:05 -0400 (EDT)
Received: from klamath.dyndns.org (CPE002078144ae0.cpe.net.cable.rogers.com [24.102.202.35])
	by postgresql.org (Postfix) with ESMTP id 7867847585D
	for <pgsql-hackers@postgresql.org>; Wed, 17 Jul 2002 16:17:57 -0400 (EDT)
Received: by klamath.dyndns.org (Postfix, from userid 1000)
	id A182C7015; Wed, 17 Jul 2002 16:17:58 -0400 (EDT)
Date: Wed, 17 Jul 2002 16:17:58 -0400
To: Tom Lane <tgl@sss.pgh.pa.us>
cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: Re: [HACKERS] error codes
Message-ID: <20020717201758.GA6846@klamath.dyndns.org>
Mail-Followup-To: Tom Lane <tgl@sss.pgh.pa.us>,
	PostgreSQL Hackers <pgsql-hackers@postgresql.org>
References: <20020717182739.GB5542@klamath.dyndns.org> <16462.1026935876@sss.pgh.pa.us>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <16462.1026935876@sss.pgh.pa.us>
User-Agent: Mutt/1.4i
From: nconway@klamath.dyndns.org (Neil Conway)
Precedence: bulk
Sender: pgsql-hackers-owner@postgresql.org
Status: OR

On Wed, Jul 17, 2002 at 03:57:56PM -0400, Tom Lane wrote:
> nconway@klamath.dyndns.org (Neil Conway) writes:
> > Should every elog() have an error code?
> 
> I believe we decided that it'd be okay to use one or two codes defined
> like "internal error", "corrupted data", etc for all the elogs that are
> not-supposed-to-happen conditions.

Ok, makes sense to me.

> > How should the backend code signal an error with an error number?
> 
> Please read some of the archived discussions about this.  All the points
> you mention have been brought up before.

Woops -- I wasn't aware that this had been discussed before, my apologies.
I'm reading the archives now...

Peter: are you planning to implement this?

Cheers,

Neil

-- 
Neil Conway <neilconway@rogers.com>
PGP Key ID: DB3C29FC

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

From pgsql-hackers-owner+M25097@postgresql.org Wed Jul 17 18:04:36 2002
Return-path: <pgsql-hackers-owner+M25097@postgresql.org>
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by candle.pha.pa.us (8.11.6/8.10.1) with ESMTP id g6HM4Ze09359
	for <pgman@candle.pha.pa.us>; Wed, 17 Jul 2002 18:04:35 -0400 (EDT)
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by postgresql.org (Postfix) with SMTP
	id AD154475D78; Wed, 17 Jul 2002 18:04:29 -0400 (EDT)
Received: from candle.pha.pa.us (216-55-132-35.dsl.san-diego.abac.net [216.55.132.35])
	by postgresql.org (Postfix) with ESMTP id 5541A475C95
	for <pgsql-hackers@postgresql.org>; Wed, 17 Jul 2002 18:04:21 -0400 (EDT)
Received: (from pgman@localhost)
	by candle.pha.pa.us (8.11.6/8.10.1) id g6HM4Hi09355;
	Wed, 17 Jul 2002 18:04:17 -0400 (EDT)
From: Bruce Momjian <pgman@candle.pha.pa.us>
Message-ID: <200207172204.g6HM4Hi09355@candle.pha.pa.us>
Subject: Re: [HACKERS] error codes
In-Reply-To: <20020717182739.GB5542@klamath.dyndns.org>
To: Neil Conway <nconway@klamath.dyndns.org>
Date: Wed, 17 Jul 2002 18:04:17 -0400 (EDT)
cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
X-Mailer: ELM [version 2.4ME+ PL99 (25)]
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=ELM1026943457-25421-1_
Content-Transfer-Encoding: 7bit
Precedence: bulk
Sender: pgsql-hackers-owner@postgresql.org
Status: OR

--ELM1026943457-25421-1_
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII


Neil, attached are three email messages dealing with error message
wording.

I like Tom's idea of coding only the messages that are common/user
errors and leaving the others with a catch-all code.

We now have more elog levels in 7.3, so it should be easier to classify
the messages.

I can see this job as several parts:

---------------------------------------------------------------------------

Cleanup of error wording, removal of function names.  See attached
emails for possible standard.

---------------------------------------------------------------------------

Reporting of file, line, function reporting using GUC/SET variable.  For
function names I see in the gcc 3.1 docs at
http://gcc.gnu.org/onlinedocs/gcc-3.1/cpp/Standard-Predefined-Macros.html:

	C99 introduces __func__, and GCC has provided __FUNCTION__ for a long
	time. Both of these are strings containing the name of the current
	function (there are slight semantic differences; see the GCC manual).
	Neither of them is a macro; the preprocessor does not know the name of
	the current function. They tend to be useful in conjunction with
	__FILE__ and __LINE__, though.

My gcc 2.95 (gcc version 2.95.2 19991024) supports both __FUNCTION__ and
__func__, even though they are not documented in the info manual pages I
have.  I think we will need a configure.in test for this because it
isn't a macro you can #ifdef.

---------------------------------------------------------------------------

Actual error code numbers/letters.  I think the new elog levels will
help with this.  We have to decide if we want error numbers, or some
pneumonic like NOATTR or CONSTVIOL.  I suggest the latter.

---------------------------------------------------------------------------

I think we have plenty of time to get this done for 7.3.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

--ELM1026943457-25421-1_
Content-Transfer-Encoding: 7bit
Content-Type: text/plain
Content-Disposition: inline; filename="/bjm/error"

>From pgsql-hackers-owner+M16120=candle.pha.pa.us=pgman@postgresql.org Fri Nov 30 12:14:19 2001
Return-path: <pgsql-hackers-owner+M16120=candle.pha.pa.us=pgman@postgresql.org>
Received: from rs.postgresql.org (server1.pgsql.org [64.39.15.238] (may be forged))
	by candle.pha.pa.us (8.11.6/8.10.1) with ESMTP id fAUIEIR21802
	for <pgman@candle.pha.pa.us>; Fri, 30 Nov 2001 13:14:18 -0500 (EST)
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by rs.postgresql.org (8.11.6/8.11.6) with ESMTP id fAUI6ER13094
	for <pgman@candle.pha.pa.us>; Fri, 30 Nov 2001 12:11:00 -0600 (CST)
	(envelope-from pgsql-hackers-owner+M16120=candle.pha.pa.us=pgman@postgresql.org)
Received: from moutvdom01.kundenserver.de (moutvdom01.kundenserver.de [195.20.224.200])
	by postgresql.org (8.11.3/8.11.4) with ESMTP id fAUI58m98870
	for <pgsql-hackers@postgresql.org>; Fri, 30 Nov 2001 13:05:08 -0500 (EST)
	(envelope-from peter_e@gmx.net)
Received: from [195.20.224.208] (helo=mrvdom01.schlund.de)
	by moutvdom01.kundenserver.de with esmtp (Exim 2.12 #2)
	id 169s27-00049P-00
	for pgsql-hackers@postgresql.org; Fri, 30 Nov 2001 19:05:07 +0100
Received: from p3e9e6fa2.dip0.t-ipconnect.de ([62.158.111.162])
	by mrvdom01.schlund.de with esmtp (Exim 2.12 #2)
	id 169s21-0001UP-00
	for pgsql-hackers@postgresql.org; Fri, 30 Nov 2001 19:05:03 +0100
Date: Fri, 30 Nov 2001 19:12:16 +0100 (CET)
From: Peter Eisentraut <peter_e@gmx.net>
X-Sender: <peter@peter.localdomain>
To: PostgreSQL Development <pgsql-hackers@postgresql.org>
Subject: [HACKERS] Backend error message style issues
Message-ID: <Pine.LNX.4.30.0111292302020.609-100000@peter.localdomain>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Precedence: bulk
Sender: pgsql-hackers-owner@postgresql.org
Status: ORr

Now that we've gone through nearly one development cycle with national
language support, I'd like to bring up a number of issues concerning the
style of the backend error messages that make life difficult, but probably
not only for the translators but for users as well.  Not all of these are
strictly translation issues, but the message catalogs make for a good
overview of what's going on.

I hope we can work through all of these during the next development
period.

Prefixing messages with command names
-------------------------------------

For instance,

| CREATE DATABASE: permission denied

This "command: message" style is typical for command-line programs and
it's pretty useful there if you run many commands in a pipe.  The same
usefulness could probably be derived if you run many SQL commands in a
function.  (Just "permission denied" would be very confusing there!)

If we want to use that style we should make it consistent and we should
automate it.  Via the "command tag" mechanism we already know what command
we're executing, so we can automatically prefix all messages that way.  It
could even be switched off by the user if it's deemed annoying.


Prefixing messages with function names
--------------------------------------

The function names obviously have no meaning to the user.  It is claimed
that they allow a developer to locate the place the error was raised
faster, but that's only half the truth.  Firstly, this whole thing doesn't
work if the displayed name of the function was actually passed in from
elsewhere.  Then it takes you three times longer to locate the source
because you *think* you know where it was but it's not there.  Secondly,
a developer doesn't have the need to locate every error.  For instance,

| ExecAppend: rejected due to CHECK constraint foo

There's no need to debug anything there, it's a perfectly normal use
situation.

I think the key here is to distinguish error messages that are perfectly
normal user-level events from messages which really represent an "assert
failure, but continue gracefully", such as

| initGISTstate: numberOfAttributes %d > %d

The latter could better be written something like

| BETTER_BE_TRUE(index->rd_att->natts > INDEX_MAX_KEYS);

we could lead to an error message in the style of an assert failure,
including the expression in question and file and line information (and
bug reporting suggestions).  This way the developer doesn't have to write
any message text at all but still gets much better information to locate
the source.  (E.g., note that the tested variable isn't even called
"numberOfAttributes".)

The exact API could be tuned to include some other information such as an
informal message, but I think something along these lines needs to be
worked out.


Quoting
-------

Which is better:

function '%s' not found
function "%s" not found
function %s not found

I think two kinds of quotes is looking messy.  Personal suggestion:
double quotes.


Capitalization and punctuation
------------------------------

Which one?

ERROR:  Permission denied.
ERROR:  Permission denied
ERROR:  permission denied

I have personally used the GNU-recommended way which is the third, mostly
just because it is *some* standardized way.  I don't have a strong feeling
about the initial capitalization, but I'm against the periods except when
the message is really a sentence and it contains some other punctuation
(commas, etc.) or the message consists of more than one sentence.


Grammatical structure and choice of words
-----------------------------------------

There are many others besides the above choices:

ERROR: Permission was denied.
ERROR: You don't have permission to do <task>.
ERROR: Permission to do <task> was denied.
ERROR: <task>: Permission denied

In other cases there's a sea of possibilities:

couldn't find THING
can't find THING
THING wasn't found
unable to locate THING
lookup of THING failed
THING doesn't exist

Strictly speaking, there are at least four different meanings among those
six messages, yet they're used mostly randomly.

There are a number of things to think about here: active vs passive, can
vs could, complete sentence vs telegram style, use of colons, addressing
the user with "you [cannot...]".

And please let's not have the program talk in the "I"-form ("I have rolled
back the current transaction ...").



More esoteric discussions are also possible, but I'm going to postpone
those. ;-)  However, I think it's worth working on this and perhaps
putting together a "manual of style" that applies to all parts of
PostgreSQL.  This would significantly improve the overall perceived
quality.  Some projects like KDE, GNU, and GCC have teams that discuss
these kinds of things and it's definitely showing.

-- 
Peter Eisentraut   peter_e@gmx.net


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

>From pgsql-hackers-owner+M16128=candle.pha.pa.us=pgman@postgresql.org Fri Nov 30 13:39:41 2001
Return-path: <pgsql-hackers-owner+M16128=candle.pha.pa.us=pgman@postgresql.org>
Received: from rs.postgresql.org (server1.pgsql.org [64.39.15.238] (may be forged))
	by candle.pha.pa.us (8.11.6/8.10.1) with ESMTP id fAUJdfR29066
	for <pgman@candle.pha.pa.us>; Fri, 30 Nov 2001 14:39:41 -0500 (EST)
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by rs.postgresql.org (8.11.6/8.11.6) with ESMTP id fAUJXkR15701
	for <pgman@candle.pha.pa.us>; Fri, 30 Nov 2001 13:36:17 -0600 (CST)
	(envelope-from pgsql-hackers-owner+M16128=candle.pha.pa.us=pgman@postgresql.org)
Received: from corvette.mascari.com (dhcp065-024-158-068.columbus.rr.com [65.24.158.68])
	by postgresql.org (8.11.3/8.11.4) with ESMTP id fAUJMnm01940
	for <pgsql-hackers@postgresql.org>; Fri, 30 Nov 2001 14:22:49 -0500 (EST)
	(envelope-from mascarm@mascari.com)
Received: from mascari.com (ferrari.mascari.com [192.168.2.1])
	by corvette.mascari.com (8.9.3/8.9.3) with ESMTP id OAA20637;
	Fri, 30 Nov 2001 14:16:52 -0500
Message-ID: <3C07DBAD.A9735975@mascari.com>
Date: Fri, 30 Nov 2001 14:19:09 -0500
From: Mike Mascari <mascarm@mascari.com>
Organization: Mascari Development Inc.
X-Mailer: Mozilla 4.77 [en] (WinNT; U)
X-Accept-Language: en
MIME-Version: 1.0
To: Peter Eisentraut <peter_e@gmx.net>
cc: PostgreSQL Development <pgsql-hackers@postgresql.org>
Subject: Re: [HACKERS] Backend error message style issues
References: <Pine.LNX.4.30.0111292302020.609-100000@peter.localdomain>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Precedence: bulk
Sender: pgsql-hackers-owner@postgresql.org
Status: OR

Peter Eisentraut wrote:
> 
> Now that we've gone through nearly one development cycle with national
> language support, I'd like to bring up a number of issues concerning the
> style of the backend error messages that make life difficult, but probably
> not only for the translators but for users as well.  Not all of these are
> strictly translation issues, but the message catalogs make for a good
> overview of what's going on.

For what its worth, Oracle 8 ships with an error.txt file which
dictates the message standards to which their products comply.
Roughly:

Size Of Message:
---------------

Cannot exceed 76 characters, even when embedded format specifiers
are apart of the message. Only 
start-up and system-dependent messages can exceed 76 characters.

Simple Language:
---------------

Use non-cryptic messages and overly technical language.

Upper vs. Lowercase:
-------------------

Use uppercase for commands and keywords, lowercase for message
wording, including the first letter (which agrees with your use,
Peter).

Commands, Keywords, Parameter Values:
------------------------------------

When possible, give the command, keyword and parameters used in the
message. 

BAD: The relation could not be created
GOOD: CREATE TABLE failed for table "foo" because the disk is full

Period:
------

Do not end messages with a period (also agrees with your
conclusion).

Numbers:
-------

Don't enclose numbers with special characters. For example:

BAD: rows returned by subquery (3) exceeded limit (1)
GOOD: the subquery returned 3 rows exceeding the 1 row limit

Quotes:
------

Don't use single or double quotes to emphasize a text variable or
command

Single Quotes:
-------------

Never use them.

Double Quotes:
-------------

Always and only use them to identify database objects. 

BAD: Unable to drop table employees
GOOD: DROP TABLE of "employees" failed due to referential integrity
constraints

Ellipses:
--------

Don't use them. 

BAD: Unable to drop column mascarm.employees.salary
GOOD: ALTER TABLE was unable to drop the column "salary" table
"employees" schema "mascarm"

Parentheses:
-----------

Always and only use parentheses for constraint names

BAD: not null constraint ri_employees violated
GOOD: not null constraint (ri_employees) violated

Brackets:
--------

Always and only used for program arguments

Grammar:
-------

Use complete sentences whenever possible without the trailing
period. Don't use multiple sentences. Use the active voice. Don't
use an aggressive tone.

Style:
-----

Make positive suggestions. Explain what is invalid and what is
valid.

Example:

BAD: file name invalid
BETTER: COPY failed because the file name was too long

Routine names:
-------------

Do not use routine names in messages. Again, agrees with you, Peter.

FWIW, 

Mike Mascari
mascarm@mascari.com

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

>From pgsql-hackers-owner+M16130=candle.pha.pa.us=pgman@postgresql.org Fri Nov 30 14:09:48 2001
Return-path: <pgsql-hackers-owner+M16130=candle.pha.pa.us=pgman@postgresql.org>
Received: from rs.postgresql.org (server1.pgsql.org [64.39.15.238] (may be forged))
	by candle.pha.pa.us (8.11.6/8.10.1) with ESMTP id fAUK9lR02095
	for <pgman@candle.pha.pa.us>; Fri, 30 Nov 2001 15:09:48 -0500 (EST)
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by rs.postgresql.org (8.11.6/8.11.6) with ESMTP id fAUK3MR16820
	for <pgman@candle.pha.pa.us>; Fri, 30 Nov 2001 14:05:48 -0600 (CST)
	(envelope-from pgsql-hackers-owner+M16130=candle.pha.pa.us=pgman@postgresql.org)
Received: from sss.pgh.pa.us ([192.204.191.242])
	by postgresql.org (8.11.3/8.11.4) with ESMTP id fAUJnLm02954
	for <pgsql-hackers@postgresql.org>; Fri, 30 Nov 2001 14:49:21 -0500 (EST)
	(envelope-from tgl@sss.pgh.pa.us)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id fAUJnEi10307;
	Fri, 30 Nov 2001 14:49:14 -0500 (EST)
To: Peter Eisentraut <peter_e@gmx.net>
cc: PostgreSQL Development <pgsql-hackers@postgresql.org>
Subject: Re: [HACKERS] Backend error message style issues 
In-Reply-To: <Pine.LNX.4.30.0111292302020.609-100000@peter.localdomain> 
References: <Pine.LNX.4.30.0111292302020.609-100000@peter.localdomain>
Comments: In-reply-to Peter Eisentraut <peter_e@gmx.net>
	message dated "Fri, 30 Nov 2001 19:12:16 +0100"
Date: Fri, 30 Nov 2001 14:49:14 -0500
Message-ID: <10303.1007149754@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
Precedence: bulk
Sender: pgsql-hackers-owner@postgresql.org
Status: OR

Peter Eisentraut <peter_e@gmx.net> writes:
> I hope we can work through all of these during the next development
> period.

Too bad we didn't do it *before* doing a lot of translation work :-(.

Yes, I agree that a pass of rationalizing the error messages would be
useful.  Might want to think about that old bugaboo, error codes,
while we're at it.  Also the perennial complaint that "ERROR" and
"DEBUG" macros tend to conflict with other things.  As long as we're
going to touch many/all of the elog() calls, couldn't we try to clean
up all these issues?

> Which is better:

> function '%s' not found
> function "%s" not found
> function %s not found

Given that 'x' and "x" mean very different things in SQL, I think that
the first form is just plain wrong when an identifier is involved.
Unfortunately a lot of older code uses that style.  I've tried to use
double quotes in new messages, but have restrained myself from wholesale
changes of existing messages.

> More esoteric discussions are also possible, but I'm going to postpone
> those. ;-)  However, I think it's worth working on this and perhaps
> putting together a "manual of style" that applies to all parts of
> PostgreSQL.  This would significantly improve the overall perceived
> quality.

Sounds like a plan to me: put together a style guide first, and then
make a pass through the code to try to implement it.

			regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org


--ELM1026943457-25421-1_
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

--ELM1026943457-25421-1_--

From pgsql-hackers-owner+M25104@postgresql.org Wed Jul 17 18:30:49 2002
Return-path: <pgsql-hackers-owner+M25104@postgresql.org>
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by candle.pha.pa.us (8.11.6/8.10.1) with ESMTP id g6HMUme12537
	for <pgman@candle.pha.pa.us>; Wed, 17 Jul 2002 18:30:48 -0400 (EDT)
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by postgresql.org (Postfix) with SMTP
	id BF5D6475D9D; Wed, 17 Jul 2002 18:30:42 -0400 (EDT)
Received: from mail.gmx.net (mail.gmx.net [213.165.64.20])
	by postgresql.org (Postfix) with SMTP id 20611475DCB
	for <pgsql-hackers@postgresql.org>; Wed, 17 Jul 2002 18:30:35 -0400 (EDT)
Received: (qmail 9427 invoked by uid 0); 17 Jul 2002 22:30:37 -0000
Received: from pd902f0de.dip0.t-ipconnect.de (217.2.240.222)
  by mail.gmx.net (mp007-rz3) with SMTP; 17 Jul 2002 22:30:37 -0000
Date: Thu, 18 Jul 2002 00:33:22 +0200 (CEST)
From: Peter Eisentraut <peter_e@gmx.net>
X-X-Sender: peter@localhost.localdomain
To: Neil Conway <nconway@klamath.dyndns.org>
cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: Re: [HACKERS] error codes
In-Reply-To: <20020717182739.GB5542@klamath.dyndns.org>
Message-ID: <Pine.LNX.4.44.0207172108290.9047-100000@localhost.localdomain>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Precedence: bulk
Sender: pgsql-hackers-owner@postgresql.org
Status: OR

Neil Conway writes:

> I'd like to implement error codes. I think they would be pretty useful,
> although there are a few difficulties in the implementation I'd like
> to get some input on.

OK, allow me to pass on to you the accumulated wisdom on this topic. :-)

> Should every elog() have an error code?

The set of error codes should primarily be that defined by SQL99 part 2
clause 22 "Status codes" and PostgreSQL extensions that follow that
spirit.  That means that all those "can't happen" or "all is lost anyway"
types should be lumped (perhaps in some implicit way) under "internal
error".  That means, yes, an error code should be returned in every case
of an error, but it doesn't have to be a distinct error code for every
condition.

> How should the backend code signal an error with an error number?

> The problem here is that many errors will require more information
> that that, in order for the client to handle them properly. For
> example, how should a COPY indicate that an RI violation has
> occured? Ideally, we'd like to allow the client application to
> know that in line a, column b, the literal value 'c' was
> not found in the referenced column d of the referenced table d.

Precisely.  You will find that SQL99 part 2 clause 19 "Diagnostics
management" defines all the fields that form part of a diagnostic (i.e.,
error or notice).  This includes for example, fields that contain the name
and schema of the table that was involved, if appropriate.  (Again,
appropriate PostgreSQL extensions could be made.)  It is recommendable
that this scheme be followed, so PL/pgSQL and ECPG, to name some
candidates, could implement the GET DIAGNOSTICS statement as in the
standard.  (Notice that, for example, a diagnostic still contains a text
message in addition to a code.)

> How should the error number be sent to the client, and would this
> require an FE/BE change? I think we can avoid that: including the
> error number in the error message itself, make PQgetErrorMessage()
> (and similar funcs) smart enough to remove the error number, and
> add a separate function (such as PQgetErrorNumber() ) to report
> the error number, if there is one.

I would advise against trying to cram everything into a string.  Consider
the extra fields explained above.  Consider being nice to old clients.
Also, libpq allows that more than one error message might arrive per query
cycle.  Currently, the error messages are concatenated.  That won't work
anymore.  You need a new API anyway.  You need a new API for notices, too.

One possiblity to justify a protocol change is to break something else
with it, like a new copy protocol.

> On a related note, it would be nice to get a consistent style of
> punctuation for elog() messages -- currently, some of them end
> in a period (e.g. "Database xxx does not exist in the system
> catalog."), while the majority do not. Which is better?

Yup, we've talked about that some time ago.  I have a style guide mostly
worked out for discussion.

> It would be relatively easy to replace elog() with a macro of
> the form:
>
> #define elog(...) real_elog(__FILE__, __LINE__, __VA_ARGS__)
>
> And then adjust real_elog() to report that information as
> appropriate.

And it would be relatively easy to break every old compiler that way...

-- 
Peter Eisentraut   peter_e@gmx.net


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

From pgsql-hackers-owner+M25114@postgresql.org Wed Jul 17 21:57:52 2002
Return-path: <pgsql-hackers-owner+M25114@postgresql.org>
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by candle.pha.pa.us (8.11.6/8.10.1) with ESMTP id g6I1vpe07438
	for <pgman@candle.pha.pa.us>; Wed, 17 Jul 2002 21:57:52 -0400 (EDT)
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by postgresql.org (Postfix) with SMTP
	id 0E63047593C; Wed, 17 Jul 2002 21:57:47 -0400 (EDT)
Received: from houston.familyhealth.com.au (i231-006.nv.iinet.net.au [203.59.231.6])
	by postgresql.org (Postfix) with ESMTP id BA91F47585D
	for <pgsql-hackers@postgresql.org>; Wed, 17 Jul 2002 21:57:41 -0400 (EDT)
Received: (from root@localhost)
	by houston.familyhealth.com.au (8.11.6/8.11.6) id g6I1viW22817
	for pgsql-hackers@postgresql.org; Thu, 18 Jul 2002 09:57:44 +0800 (WST)
	(envelope-from chriskl@familyhealth.com.au)
Received: from mariner (mariner.internal [192.168.0.101])
	by houston.familyhealth.com.au (8.11.6/8.9.3) with SMTP id g6I1vhV22728;
	Thu, 18 Jul 2002 09:57:43 +0800 (WST)
From: "Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
To: "Neil Conway" <nconway@klamath.dyndns.org>,
   "PostgreSQL Hackers" <pgsql-hackers@postgresql.org>
Subject: Re: [HACKERS] error codes
Date: Thu, 18 Jul 2002 09:57:56 +0800
Message-ID: <GNELIHDDFBOCMGBFGEFOOEDECDAA.chriskl@familyhealth.com.au>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
In-Reply-To: <20020717182739.GB5542@klamath.dyndns.org>
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Importance: Normal
X-scanner: scanned by Inflex 0.1.5c - (http://www.inflex.co.za/)
Precedence: bulk
Sender: pgsql-hackers-owner@postgresql.org
Status: OR

> Should every elog() have an error code? I'm not sure -- there are many
> elog() calls that will never been seen by the user, since the error
> they represent will be caught before control reaches the elog (e.g.
> parse errors, internal consistency checks, multiple elog(ERROR)
> for the same user error, etc.) Perhaps for those error messages
> that don't have numbers, we could just give them ERRNO_UNKNOWN or
> a similar constant.

It might be cool to a little command utility "pg_error" or whatever that you
pass an error code to and it prints out a very detailed description of the
problem...

Chris


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

From pgsql-hackers-owner+M25119@postgresql.org Thu Jul 18 04:01:40 2002
Return-path: <pgsql-hackers-owner+M25119@postgresql.org>
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by candle.pha.pa.us (8.11.6/8.10.1) with ESMTP id g6I81de14995
	for <pgman@candle.pha.pa.us>; Thu, 18 Jul 2002 04:01:40 -0400 (EDT)
Received: from postgresql.org (postgresql.org [64.49.215.8])
	by postgresql.org (Postfix) with SMTP
	id 38C49475E0D; Thu, 18 Jul 2002 04:01:33 -0400 (EDT)
Received: from smxsat1.smxs.net (smxsat1.smxs.net [213.150.10.1])
	by postgresql.org (Postfix) with ESMTP id 82A1B475DB6
	for <pgsql-hackers@postgresql.org>; Thu, 18 Jul 2002 04:01:26 -0400 (EDT)
Received: from m01x1.s-mxs.net [10.3.55.201]
	by smxsat1.smxs.net
	over TLS secured channel
	with XWall v3.21e ;
	Thu, 18 Jul 2002 10:01:23 +0200
Received: from m0102.s-mxs.net [10.3.55.2]
	by m01x1.s-mxs.net
	with XWall v3.21b ;
	Thu, 18 Jul 2002 10:01:21 +0200
Received: from m0114.s-mxs.net ([10.3.55.14]) by m0102.s-mxs.net with Microsoft SMTPSVC(5.0.2195.4453);
  Thu, 18 Jul 2002 10:01:20 +0200
X-MimeOLE: Produced By Microsoft Exchange V6.0.5762.3
content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Subject: Re: [HACKERS] error codes
Date: Thu, 18 Jul 2002 10:01:20 +0200
Message-ID: <46C15C39FEB2C44BA555E356FBCD6FA4961E24@m0114.s-mxs.net>
Thread-Topic: [HACKERS] error codes
Thread-Index: AcIt3fXLfLUm5ueDTfKp02tm+iyO0AAUPF/Q
From: "Zeugswetter Andreas SB SD" <ZeugswetterA@spardat.at>
To: "Bruce Momjian" <pgman@candle.pha.pa.us>,
   "Neil Conway" <nconway@klamath.dyndns.org>
cc: "PostgreSQL Hackers" <pgsql-hackers@postgresql.org>
X-OriginalArrivalTime: 18 Jul 2002 08:01:20.0584 (UTC) FILETIME=[4D5A6480:01C22E31]
Precedence: bulk
Sender: pgsql-hackers-owner@postgresql.org
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by candle.pha.pa.us id g6I81de14995
Status: ORr


Bruce wrote:
> Actual error code numbers/letters.  I think the new elog levels will
> help with this.  We have to decide if we want error numbers, or some
> pneumonic like NOATTR or CONSTVIOL.  I suggest the latter.

Since there is an actual standard for error codes, I would strongly suggest 
to adhere. The standardized codes are SQLSTATE a char(5) (well standardized
for many classes of db errors). Also common, but not so standardized is SQLCODE 
a long (only a very few are standardized, like 100 = 'no data found').
And also sqlca. Also look at ecpg for sqlcode and sqlca.

A Quote from dec rdb:
--------------------------------------------------------------------
   o  SQLCODE-This is the original SQL error handling mechanism.
      It is an integer value. SQLCODE differentiates among errors
      (negative numbers), warnings (positive numbers), succesful
      completion (0), and a special code of 100, which means no
      data. SQLCODE is a deprecated feature of the ANSI/ISO SQL
      standard.

   o  SQLCA-This is an extension of the SQLCODE error handling
      mechanism. It contains other context information that
      supplements the SQLCODE value. SQLCA is not part of the
      ANSI/ISO SQL standard. However, many foreign databases such
      as DB2 and ORACLE RDBMS have defined proprietary semantics and
      syntax to implement it.

   o  SQLSTATE-This is the error handling mechanism for the ANSI/ISO
      SQL standard. The SQLSTATE value is a character string that is
      associated with diagnostic information. To use the SQLSTATE
      status parameter, you must specify the SQL92 dialect and
      compile your module using DEC Rdb Version 6.0.
--------------------------------------------------------------------

Andreas

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster