diff --git a/octodns/record/base.py b/octodns/record/base.py index 57b12ce..21dd864 100644 --- a/octodns/record/base.py +++ b/octodns/record/base.py @@ -94,25 +94,28 @@ class Record(EqualityTupleMixin): data_validator.iter_errors(data), ) for error in errors: - print('error:') # some of the jsonschema error messages are opaque and useless # to end uses, this provides a mechinism to translate them. schema = error.schema - print(f'schema={schema}') try: message = schema['$error_message'] - print(f'$error_message: message={message}') + cls.log.debug('new: $error_message=`%s`, instance=%s', message, error.instance) except KeyError: path = '.'.join(str(p) for p in error.schema_path) - print(f'$error_messages: path={path}') try: messages = schema['$error_messages'] - print(f'$error_messages: messages={messages}') + cls.log.debug('new: $error_messages=%s, path=%s', messages, path) message = messages[path] - print(f'$error_messages: message={message}') + cls.log.debug('new: $error_message=`%sr`, instance=%s', message, error.instance) + message = message.format(instance=error.instance) + cls.log.debug('new: $error_message.format=`%sr`', message) except KeyError: message = error.message - print(f'error.messages: message={message}') + cls.log.debug('new: error.message=`%sr`', message) + else: + instance = error.instance + message = message, instance=error.instance) + cls.log.debug('new: $error_message.format=`%s`', message) reasons.append(message) else: # original .validate @@ -139,7 +142,8 @@ class Record(EqualityTupleMixin): return { 'properties': { 'name': {'type': 'string'}, - 'fqdn': {'type': 'string', 'maxLength': 253}, + 'fqdn': {'type': 'string', 'maxLength': 253, + '$error_message': 'invalid fqdn, "{instance} is too long at {len(instance)}, max is 253"'}, }, 'allOf': [ { diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index 690d821..cff76de 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -583,8 +583,13 @@ class TestRecordValidation(TestCase): self.zone, name, {'ttl': 300, 'type': 'A', 'value': '1.2.3.4'} ) reason = ctx.exception.reasons[0] - self.assertTrue(reason.startswith("'xxxx")) - self.assertTrue(reason.endswith("xxxx.unit.tests.' is too long")) + print(reason) + self.assertTrue(reason.startswith('invalid fqdn, "xxxx')) + self.assertTrue( + reason.endswith( + '.unit.tests." is too long at 254 chars, max is 253' + ) + ) # label length, DNS defines max as 63 with self.assertRaises(ValidationError) as ctx: