question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't catch the ResourceNotFoundException

See original GitHub issue

Describe the bug

Hello,

I’m creating a lambda function to store some data into a DynamoDB table. Whether the table doesn’t exists. it must be created, however the specific exception class isn’t available in the lib to import or call it.

Expected Behavior

Catch the specific exception (ResourceNotFoundException)

    try:
        table = dynamodb_client.Table(TABLE_NAME)
        logger.info(table.table_status)
    except ResourceNotFoundException:
        create_table(TABLE_NAME)

Current Behavior

General expcetion catching:

    try:
        table = dynamodb_client.Table(TABLE_NAME)
        logger.info(table.table_status)
    except:
        create_table(TABLE_NAME)

Reproduction Steps

The table doesn’t exists and the function is:

    TABLE_NAME = 'newtable'
    dynamodb_client = boto3.resource('dynamodb')

    table = dynamodb_client.Table(TABLE_NAME)
    logger.info(table.table_status)

and the riased error is

botocore.errorfactory.ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the DescribeTable operation: Requested resource not found: Table: newtable not found

Possible Solution

No response

Additional Information/Context

No response

SDK version used

boto3

Environment details (OS name and version, etc.)

Ubuntu 22.04

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
corey-colecommented, Nov 7, 2022

Hi,

botocore.exceptions.ClientError seems to not intercept the botocore.errorfactory.ResourceNotFoundException exception.

I am using:

    try:
        thing = client.describe_thing(thingName=thingName)
    except client.exceptions.ResourceNotFoundException as error:
        print(error)
from botocore.exceptions import ClientError

# Assumes client is already initialized as DynamoDB client
try:
    thing = client.describe_table(TableName='does-not-exist')
except ClientError as err:
    # This will not result in a failed assertion
    assert err.response['Error']['Code'] == 'ResourceNotFoundException'
2reactions
sbarzaghialteaupcommented, Nov 8, 2022

Hi,

Edit: Don’t consider this, see my next comment.

botocore.exceptions.ClientError seems to not intercept the botocore.errorfactory.ResourceNotFoundException exception.

I am using:

    try:
        thing = client.describe_thing(thingName=thingName)
    except client.exceptions.ResourceNotFoundException as error:
        print(error)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Symfony2 can't catch ResourceNotFoundException
Try to replace Exception by ResourceNotFoundException . And don't forget use statement: <?php namespace OOOO\AdvertisingBundle\Utilities; ...
Read more >
6 Common DynamoDB Issues - Dashbird
Resource Not Found Exception. The AWS SDK can't find your table. The most common reasons for this are a typo in the table...
Read more >
Error handling with DynamoDB - AWS Documentation
This section describes runtime errors and how to handle them. ... in a Java program, you can write try-catch logic to handle a...
Read more >
Working with Items in DynamoDB - Amazon SDK for Java 1.x
How to retrieve (get), add, and update items in Amazon DynamoDB tables. ... putItem(table_name, item_values); } catch (ResourceNotFoundException e) ...
Read more >
Cannot find resource for the request getByTitile - 404
Solved: Hi I have attempted to set up a Flow using this video : https://www.youtube.com/watch?v=T6cC65YwjSI But at the send HTTP request to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found