Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.

Commit 0eb912f

Browse files
committed
Updating the error handling code for samples.
1 parent a3369b1 commit 0eb912f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+197
-148
lines changed

samples/ingredients/operations/handle_extended_operation.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ def wait_for_extended_operation(
5555
result = operation.result(timeout=timeout)
5656

5757
if operation.error_code:
58-
print(f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}", file=sys.stderr)
59-
print(f"Operation ID: {operation.name}")
58+
print(f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
59+
file=sys.stderr, flush=True)
60+
print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
6061
raise operation.exception() or RuntimeError(operation.error_message)
6162

6263
if operation.warnings:
63-
print(f"Warnings during {verbose_name}:\n", file=sys.stderr)
64+
print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
6465
for warning in operation.warnings:
65-
print(f" - {warning.code}: {warning.message}", file=sys.stderr)
66+
print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)
6667

6768
return result
6869
# </INGREDIENT>

samples/snippets/disks/autodelete_change.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ def wait_for_extended_operation(
6161
print(
6262
f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
6363
file=sys.stderr,
64+
flush=True,
6465
)
65-
print(f"Operation ID: {operation.name}")
66+
print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
6667
raise operation.exception() or RuntimeError(operation.error_message)
6768

6869
if operation.warnings:
69-
print(f"Warnings during {verbose_name}:\n", file=sys.stderr)
70+
print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
7071
for warning in operation.warnings:
71-
print(f" - {warning.code}: {warning.message}", file=sys.stderr)
72+
print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)
7273

7374
return result
7475

samples/snippets/disks/create_empty_disk.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ def wait_for_extended_operation(
6161
print(
6262
f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
6363
file=sys.stderr,
64+
flush=True,
6465
)
65-
print(f"Operation ID: {operation.name}")
66+
print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
6667
raise operation.exception() or RuntimeError(operation.error_message)
6768

6869
if operation.warnings:
69-
print(f"Warnings during {verbose_name}:\n", file=sys.stderr)
70+
print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
7071
for warning in operation.warnings:
71-
print(f" - {warning.code}: {warning.message}", file=sys.stderr)
72+
print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)
7273

7374
return result
7475

samples/snippets/disks/create_from_image.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ def wait_for_extended_operation(
6161
print(
6262
f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
6363
file=sys.stderr,
64+
flush=True,
6465
)
65-
print(f"Operation ID: {operation.name}")
66+
print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
6667
raise operation.exception() or RuntimeError(operation.error_message)
6768

6869
if operation.warnings:
69-
print(f"Warnings during {verbose_name}:\n", file=sys.stderr)
70+
print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
7071
for warning in operation.warnings:
71-
print(f" - {warning.code}: {warning.message}", file=sys.stderr)
72+
print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)
7273

7374
return result
7475

samples/snippets/disks/create_from_snapshot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ def wait_for_extended_operation(
6161
print(
6262
f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
6363
file=sys.stderr,
64+
flush=True,
6465
)
65-
print(f"Operation ID: {operation.name}")
66+
print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
6667
raise operation.exception() or RuntimeError(operation.error_message)
6768

6869
if operation.warnings:
69-
print(f"Warnings during {verbose_name}:\n", file=sys.stderr)
70+
print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
7071
for warning in operation.warnings:
71-
print(f" - {warning.code}: {warning.message}", file=sys.stderr)
72+
print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)
7273

7374
return result
7475

samples/snippets/disks/delete.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ def wait_for_extended_operation(
6161
print(
6262
f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
6363
file=sys.stderr,
64+
flush=True,
6465
)
65-
print(f"Operation ID: {operation.name}")
66+
print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
6667
raise operation.exception() or RuntimeError(operation.error_message)
6768

6869
if operation.warnings:
69-
print(f"Warnings during {verbose_name}:\n", file=sys.stderr)
70+
print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
7071
for warning in operation.warnings:
71-
print(f" - {warning.code}: {warning.message}", file=sys.stderr)
72+
print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)
7273

7374
return result
7475

samples/snippets/firewall/create.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ def wait_for_extended_operation(
6161
print(
6262
f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
6363
file=sys.stderr,
64+
flush=True,
6465
)
65-
print(f"Operation ID: {operation.name}")
66+
print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
6667
raise operation.exception() or RuntimeError(operation.error_message)
6768

6869
if operation.warnings:
69-
print(f"Warnings during {verbose_name}:\n", file=sys.stderr)
70+
print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
7071
for warning in operation.warnings:
71-
print(f" - {warning.code}: {warning.message}", file=sys.stderr)
72+
print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)
7273

7374
return result
7475

samples/snippets/firewall/delete.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ def wait_for_extended_operation(
6161
print(
6262
f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
6363
file=sys.stderr,
64+
flush=True,
6465
)
65-
print(f"Operation ID: {operation.name}")
66+
print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
6667
raise operation.exception() or RuntimeError(operation.error_message)
6768

6869
if operation.warnings:
69-
print(f"Warnings during {verbose_name}:\n", file=sys.stderr)
70+
print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
7071
for warning in operation.warnings:
71-
print(f" - {warning.code}: {warning.message}", file=sys.stderr)
72+
print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)
7273

7374
return result
7475

samples/snippets/firewall/patch.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ def wait_for_extended_operation(
6161
print(
6262
f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
6363
file=sys.stderr,
64+
flush=True,
6465
)
65-
print(f"Operation ID: {operation.name}")
66+
print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
6667
raise operation.exception() or RuntimeError(operation.error_message)
6768

6869
if operation.warnings:
69-
print(f"Warnings during {verbose_name}:\n", file=sys.stderr)
70+
print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
7071
for warning in operation.warnings:
71-
print(f" - {warning.code}: {warning.message}", file=sys.stderr)
72+
print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)
7273

7374
return result
7475

samples/snippets/images/create.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,15 @@ def wait_for_extended_operation(
6363
print(
6464
f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
6565
file=sys.stderr,
66+
flush=True,
6667
)
67-
print(f"Operation ID: {operation.name}")
68+
print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
6869
raise operation.exception() or RuntimeError(operation.error_message)
6970

7071
if operation.warnings:
71-
print(f"Warnings during {verbose_name}:\n", file=sys.stderr)
72+
print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
7273
for warning in operation.warnings:
73-
print(f" - {warning.code}: {warning.message}", file=sys.stderr)
74+
print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)
7475

7576
return result
7677

0 commit comments

Comments
 (0)