Skip to content

Commit 9f86cfd

Browse files
committed
fix: improve error messages when validating extensions
This commit changes the messages produced when validating extension names and values, including the offending name or value in the message, and including text from the CloudEvent specification, or a link to the type system. Fixes: #364 Signed-off-by: Lance Ball <lball@redhat.com>
1 parent 132f052 commit 9f86cfd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: src/event/cloudevent.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,18 @@ export class CloudEvent implements CloudEventV1, CloudEventV03 {
106106
// Extension names should only allow lowercase a-z and 0-9 in the name
107107
// names should not exceed 20 characters in length
108108
if (!key.match(/^[a-z0-9]{1,20}$/) && strict) {
109-
throw new ValidationError("invalid extension name");
109+
throw new ValidationError(`invalid extension name: ${key}
110+
CloudEvents attribute names MUST consist of lower-case letters ('a' to 'z')
111+
or digits ('0' to '9') from the ASCII character set. Attribute names SHOULD
112+
be descriptive and terse and SHOULD NOT exceed 20 characters in length.`);
110113
}
111114

112115
// Value should be spec compliant
113116
// https://github.com/cloudevents/spec/blob/master/spec.md#type-system
114117
if (!isValidType(value) && strict) {
115-
throw new ValidationError("invalid extension value");
118+
throw new ValidationError(`invalid extension value: ${value}
119+
Extension values must conform to the CloudEvent type system.
120+
See: https://github.com/cloudevents/spec/blob/v1.0/spec.md#type-system`);
116121
}
117122

118123
this[key] = value;

0 commit comments

Comments
 (0)