Skip to content

fix(samples): raise the caught ServerResponseError instead of undefined rError - #1899

Open
herniqeu wants to merge 1 commit into
tableau:masterfrom
herniqeu:fix/sample-raise-server-error
Open

herniqeu wants to merge 1 commit into
tableau:masterfrom
herniqeu:fix/sample-raise-server-error

Conversation

@herniqeu

@herniqeu herniqeu commented Nov 1, 2026

Copy link
Copy Markdown

Problem

create_group.py has two handlers. The second one binds the exception as serverError:

except ServerResponseError as serverError:
    if serverError.code == "409011":
        print(f"user {user.name} is already a member of group {group.name}")
    else:
        raise rError                      # <- name from the first handler

rError is the name bound by the first handler, earlier in the function. Python deletes the exception name at the end of an except block, so at this point rError does not exist and every failure other than 409011 becomes:

NameError: name 'rError' is not defined

which is precisely the diagnostic the sample should be printing.

Fix

raise serverError — re-raise the error actually caught here. The first handler keeps raise rError (valid: it is inside its own except block).

Verification

python3 -m pyflakes samples/create_group.py

  • before: undefined name 'rError' (line 83)
  • after: gone, and no new undefined name

Achado com analise estatica (pyflakes) e leitura do chamador; verificado antes/depois do patch. Commit com Signed-off-by.

In the second error handler of create_group.py the except clause binds
`serverError`, but the re-raise uses `rError`, the name bound by the first
handler further up. Python deletes the exception name when the except block
ends, so `rError` is not defined there: every API error other than 409011
surfaced as NameError instead of the server message.

Verified with pyflakes: undefined name 'rError' gone, no new undefined name.

Signed-off-by: Henrique Godoy <95002561+herniqeu@users.noreply.github.com>
@salesforce-cla

salesforce-cla Bot commented Nov 1, 2026

Copy link
Copy Markdown

Thanks for the contribution! Before we can merge this, we need @herniqeu to sign the Salesforce Inc. Contributor License Agreement.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant