From d78b5701ea27536c4b1002a186a9abfdefccde1c Mon Sep 17 00:00:00 2001 From: Kamal Aboul-Hosn Date: Tue, 14 Mar 2023 08:37:05 -0400 Subject: [PATCH] Samples: Fix schema exception handling (#1520) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * samples: schema evolution * samples: schema evolution * Format fixes * Fix documentation for field. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Add back in working asserts * Formatting fixes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Version/delete fixes * samples: schema evolution * samples: schema evolution * Format fixes * Fix documentation for field. * Add back in working asserts * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Formatting fixes * Version/delete fixes * samples: Schema evolution (#1499) * samples: schema evolution * samples: schema evolution * Format fixes * Fix documentation for field. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Add back in working asserts * Formatting fixes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Version/delete fixes * samples: schema evolution * samples: schema evolution * Format fixes * Fix documentation for field. * Add back in working asserts * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Formatting fixes * Version/delete fixes --------- Co-authored-by: Owl Bot * Minor fixes for comments * samples: Schema evolution (#1499) * samples: schema evolution * samples: schema evolution * Format fixes * Fix documentation for field. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Add back in working asserts * Formatting fixes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Version/delete fixes * samples: schema evolution * samples: schema evolution * Format fixes * Fix documentation for field. * Add back in working asserts * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Formatting fixes * Version/delete fixes --------- Co-authored-by: Owl Bot * Fix rollback example * Formatting * Formatting and wording fixes * Add new schemas to test directory * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Samples: Fix exception handling * fix: Set x-goog-request-params for streaming pull request * Revert "fix: Set x-goog-request-params for streaming pull request" This reverts commit 3185a3e9d48680d75cc70745f7ea0048d726556b. --------- Co-authored-by: Owl Bot --- .../src/main/java/pubsub/CommitAvroSchemaExample.java | 6 +++--- .../src/main/java/pubsub/CommitProtoSchemaExample.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/snippets/src/main/java/pubsub/CommitAvroSchemaExample.java b/samples/snippets/src/main/java/pubsub/CommitAvroSchemaExample.java index e6ac8f278..8f24e75a2 100644 --- a/samples/snippets/src/main/java/pubsub/CommitAvroSchemaExample.java +++ b/samples/snippets/src/main/java/pubsub/CommitAvroSchemaExample.java @@ -18,7 +18,7 @@ // [START pubsub_commit_avro_schema] -import com.google.api.gax.rpc.AlreadyExistsException; +import com.google.api.gax.rpc.NotFoundException; import com.google.cloud.pubsub.v1.SchemaServiceClient; import com.google.pubsub.v1.ProjectName; import com.google.pubsub.v1.Schema; @@ -60,8 +60,8 @@ public static Schema commitAvroSchemaExample(String projectId, String schemaId, System.out.println("Committed a schema using an Avro schema:\n" + schema); return schema; - } catch (AlreadyExistsException e) { - System.out.println(schemaName + "already exists."); + } catch (NotFoundException e) { + System.out.println(schemaName + "does not exist."); return null; } } diff --git a/samples/snippets/src/main/java/pubsub/CommitProtoSchemaExample.java b/samples/snippets/src/main/java/pubsub/CommitProtoSchemaExample.java index b32de29dc..e609b9a5f 100644 --- a/samples/snippets/src/main/java/pubsub/CommitProtoSchemaExample.java +++ b/samples/snippets/src/main/java/pubsub/CommitProtoSchemaExample.java @@ -18,7 +18,7 @@ // [START pubsub_commit_proto_schema] -import com.google.api.gax.rpc.AlreadyExistsException; +import com.google.api.gax.rpc.NotFoundException; import com.google.cloud.pubsub.v1.SchemaServiceClient; import com.google.pubsub.v1.ProjectName; import com.google.pubsub.v1.Schema; @@ -60,8 +60,8 @@ public static Schema commitProtoSchemaExample(String projectId, String schemaId, System.out.println("Committed a schema using a protobuf schema:\n" + schema); return schema; - } catch (AlreadyExistsException e) { - System.out.println(schemaName + "already exists."); + } catch (NotFoundException e) { + System.out.println(schemaName + "does not exist."); return null; } }