ploomber / soopervisor

☁️ Export Ploomber pipelines to Kubernetes (Argo), Airflow, AWS Batch, SLURM, and Kubeflow.
https://soopervisor.readthedocs.io
Apache License 2.0
45 stars 18 forks source link

try except error #61

Closed edublancas closed 2 years ago

edublancas commented 2 years ago

I found an issue with the telemetry changes to the CLI

        try:
            backend = Backend(config.get_backend(env_name))

            telemetry.log_api("soopervisor_export_started",
                              metadata={
                                  'type': backend,
                                  'input_args': input_args
                              })

            until = None

            if until_build:
                until = 'build'

            # TODO: ignore mode if using aws lambda, raised exception if value
            # is not the default
            if backend == Backend.aws_lambda:
                mode = None

            Exporter = exporter.for_backend(backend)

            Exporter('soopervisor.yaml',
                     env_name=env_name).export(mode=mode,
                                               until=until,
                                               skip_tests=skip_tests,
                                               ignore_git=ignore_git)
            telemetry.log_api("soopervisor_export_success",
                              metadata={
                                  'type': backend,
                                  'input_args': input_args
                              })
        except Exception as e:
            telemetry.log_api("soopervisor_export_error",
                              metadata={
>                                 'type': backend,
                                  'input_args': input_args,
                                  'error': e
                              })
E           UnboundLocalError: local variable 'backend' referenced before assignment

/Users/Edu/dev/soopervisor/src/soopervisor/cli.py:133: UnboundLocalError

the try block should only have the call to .export, everything else should be outside:

# prepare stuff
try:
    # call to .export
except:
   # log error
else:
   # telemetry soopervisor_export_success

I added a (failing) test case in the telemetry-error branch

idomic commented 2 years ago

The error raised isn't of this type for some reason, I just compared the output. Check out the branch.

edublancas commented 2 years ago

fixed in 308ba1d9bad86cc2a9fe72d5b6e0e6b0d4da3fbd