Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c4010d5

Browse files
author
daniel
committed
Fix KeyError exception when project has no logs
1 parent c7a3957 commit c4010d5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cloud_logging/api/list_logs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
# [START all]
2727
import argparse
28+
import sys
2829

2930
from googleapiclient import discovery
3031
from oauth2client.client import GoogleCredentials
@@ -36,6 +37,9 @@ def list_logs(project_id, logging_service):
3637

3738
while request:
3839
response = request.execute()
40+
if len(response)==0:
41+
print "No logs found in project {0}".format(project_id)
42+
sys.exit(1)
3943
for log in response['logs']:
4044
print(log['name'])
4145

0 commit comments

Comments
 (0)