Skip to content

Commit

Permalink
fix: Add line breaks to error message
Browse files Browse the repository at this point in the history
Adds line breaks to the error message when a schema is not found
as described in issue confluentinc#7205.
  • Loading branch information
cadonna committed Mar 31, 2021
1 parent 3343763 commit 8aaf6d6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,25 @@ private static SchemaResult notFound(final String topicName, final boolean isKey
+ "Possible causes include:"
+ System.lineSeparator()
+ "- The topic itself does not exist"
+ System.lineSeparator()
+ "\t-> Use SHOW TOPICS; to check"
+ System.lineSeparator()
+ "- Messages on the topic are not serialized using a format Schema Registry supports"
+ System.lineSeparator()
+ "\t-> Use PRINT '" + topicName + "' FROM BEGINNING; to verify"
+ System.lineSeparator()
+ "- Messages on the topic have not been serialized using a Confluent Schema "
+ "Registry supported serializer"
+ System.lineSeparator()
+ "\t-> See " + DocumentationLinks.SR_SERIALISER_DOC_URL
+ System.lineSeparator()
+ "- The schema is registered on a different instance of the Schema Registry"
+ System.lineSeparator()
+ "\t-> Use the REST API to list available subjects"
+ "\t" + DocumentationLinks.SR_REST_GETSUBJECTS_DOC_URL
+ System.lineSeparator()
+ "- You do not have permissions to access the Schema Registry.Subject: " + subject
+ System.lineSeparator()
+ "\t-> See " + DocumentationLinks.SCHEMA_REGISTRY_SECURITY_DOC_URL));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ public void shouldReturnErrorFromGetValueSchemaIfNotFound() throws Exception {
// Then:
assertThat(result.schemaAndId, is(Optional.empty()));
assertThat(result.failureReason, is(not(Optional.empty())));
assertThat(result.failureReason.get().getMessage(), containsString(
"Schema for message values on topic " + TOPIC_NAME
+ " does not exist in the Schema Registry."));
verifyFailureMessageForValue(result);
}

@Test
Expand All @@ -180,9 +178,7 @@ public void shouldReturnErrorFromGetKeySchemaIfNotFound() throws Exception {
// Then:
assertThat(result.schemaAndId, is(Optional.empty()));
assertThat(result.failureReason, is(not(Optional.empty())));
assertThat(result.failureReason.get().getMessage(), containsString(
"Schema for message keys on topic " + TOPIC_NAME
+ " does not exist in the Schema Registry."));
verifyFailureMessageForKey(result);
}

@Test
Expand All @@ -198,9 +194,7 @@ public void shouldReturnErrorFromGetValueWithIdSchemaIfNotFound() throws Excepti
// Then:
assertThat(result.schemaAndId, is(Optional.empty()));
assertThat(result.failureReason, is(not(Optional.empty())));
assertThat(result.failureReason.get().getMessage(), containsString(
"Schema for message values on topic " + TOPIC_NAME
+ " does not exist in the Schema Registry."));
verifyFailureMessageForValue(result);
}

@Test
Expand All @@ -216,9 +210,7 @@ public void shouldReturnErrorFromGetKeyWithIdSchemaIfNotFound() throws Exception
// Then:
assertThat(result.schemaAndId, is(Optional.empty()));
assertThat(result.failureReason, is(not(Optional.empty())));
assertThat(result.failureReason.get().getMessage(), containsString(
"Schema for message keys on topic " + TOPIC_NAME
+ " does not exist in the Schema Registry."));
verifyFailureMessageForKey(result);
}

@Test
Expand All @@ -234,9 +226,7 @@ public void shouldReturnErrorFromGetValueIfUnauthorized() throws Exception {
// Then:
assertThat(result.schemaAndId, is(Optional.empty()));
assertThat(result.failureReason, is(not(Optional.empty())));
assertThat(result.failureReason.get().getMessage(), containsString(
"Schema for message values on topic " + TOPIC_NAME
+ " does not exist in the Schema Registry."));
verifyFailureMessageForValue(result);
}

@Test
Expand All @@ -252,9 +242,7 @@ public void shouldReturnErrorFromGetKeyIfUnauthorized() throws Exception {
// Then:
assertThat(result.schemaAndId, is(Optional.empty()));
assertThat(result.failureReason, is(not(Optional.empty())));
assertThat(result.failureReason.get().getMessage(), containsString(
"Schema for message keys on topic " + TOPIC_NAME
+ " does not exist in the Schema Registry."));
verifyFailureMessageForKey(result);
}

@Test
Expand All @@ -270,9 +258,7 @@ public void shouldReturnErrorFromGetValueIfForbidden() throws Exception {
// Then:
assertThat(result.schemaAndId, is(Optional.empty()));
assertThat(result.failureReason, is(not(Optional.empty())));
assertThat(result.failureReason.get().getMessage(), containsString(
"Schema for message values on topic " + TOPIC_NAME
+ " does not exist in the Schema Registry."));
verifyFailureMessageForValue(result);
}

@Test
Expand All @@ -288,9 +274,35 @@ public void shouldReturnErrorFromGetKeyIfForbidden() throws Exception {
// Then:
assertThat(result.schemaAndId, is(Optional.empty()));
assertThat(result.failureReason, is(not(Optional.empty())));
assertThat(result.failureReason.get().getMessage(), containsString(
"Schema for message keys on topic " + TOPIC_NAME
+ " does not exist in the Schema Registry."));
verifyFailureMessageForKey(result);
}

private void verifyFailureMessageForKey(final SchemaResult result) {
verifyFailureMessage(result, true);
}

private void verifyFailureMessageForValue(final SchemaResult result) {
verifyFailureMessage(result, false);
}

private void verifyFailureMessage(final SchemaResult result,
final boolean isKey) {
final String keyOrValue = isKey ? "keys" : "values";
final String keyOrValueSuffix = isKey ? "key" : "value";
assertThat(result.failureReason.get().getMessage(), is(
"Schema for message " + keyOrValue + " on topic " + TOPIC_NAME + " does not exist in the Schema Registry.Subject: "
+ TOPIC_NAME + "-" + keyOrValueSuffix + System.lineSeparator()
+ "Possible causes include:" + System.lineSeparator()
+ "- The topic itself does not exist" + System.lineSeparator()
+ "\t-> Use SHOW TOPICS; to check" + System.lineSeparator()
+ "- Messages on the topic are not serialized using a format Schema Registry supports" + System.lineSeparator()
+ "\t-> Use PRINT '" + TOPIC_NAME + "' FROM BEGINNING; to verify" + System.lineSeparator()
+ "- Messages on the topic have not been serialized using a Confluent Schema Registry supported serializer" + System.lineSeparator()
+ "\t-> See https://docs.confluent.io/current/schema-registry/docs/serializer-formatter.html" + System.lineSeparator()
+ "- The schema is registered on a different instance of the Schema Registry" + System.lineSeparator()
+ "\t-> Use the REST API to list available subjects\thttps://docs.confluent.io/current/schema-registry/docs/api.html#get--subjects" + System.lineSeparator()
+ "- You do not have permissions to access the Schema Registry.Subject: " + TOPIC_NAME + "-" + keyOrValueSuffix + System.lineSeparator()
+ "\t-> See https://docs.confluent.io/current/schema-registry/docs/security.html"));
}

@Test
Expand Down

0 comments on commit 8aaf6d6

Please sign in to comment.