snyk-labs / pysnyk

A Python client for the Snyk API.
https://snyk.docs.apiary.io/
MIT License
88 stars 116 forks source link

[BUG]: Exception Raised When Getting Dependency Graph for Project That Isn't Using a Supported Package Manager #173

Open ErikOwen opened 1 year ago

ErikOwen commented 1 year ago

Is there an existing issue for this?

Description of the bug

I was using the pysnyk package to pull a dependency graph for a project that had a project type of dockerfile, and it raised this exception:

ValueError: Argument for snyk.models.DependencyGraph.from_dict method should be a dict instance

This exception isn't intuitive, and at first glance it appears that the Snyk SDK wasn't compatible with the response from the Snyk API.

I raised a ticket with Snyk support, and I was told that the reason the exception was being raised was because the dependency graph API endpoint only supports specific package managers (see here).

The Snyk API should raise a more helpful exception to help end users understand that the project they are trying to get the dependency graph for isn't currently supported.

Steps To Reproduce

import snyk # from https://pypi.org/project/pysnyk/
snyk_client = snyk.SnykClient("<put-snyk-api-token-here>")
org = snyk_client.organizations.get("<put-org-id-with-project-that-has-dockerfile-as-type>")
[p.dependency_graph for p in org.projects.all()]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <listcomp>
  File "/Path/to/virtual_env/.venv/lib/python3.9/site-packages/snyk/models.py", line 647, in dependency_graph
    return Manager.factory(DependencyGraph, self.organization.client, self).all()
  File "/Path/to/virtual_env/.venv/lib/python3.9/site-packages/snyk/managers.py", line 377, in all
    return self.klass.from_dict(dependency_data["depGraph"])
  File "<string>", line 43, in from_dict
ValueError: Argument for snyk.models.DependencyGraph.from_dict method should be a dict instance

Additional Information

No response