Skip to content

Commit d483ce8

Browse files
committed
improve error messages for artist creation
1 parent 2a01552 commit d483ce8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5151
* Fixed `compas_blender.artists.VolMeshArtist.draw` and `compas_blender.artists.VolMeshArtist.draw_cells`.
5252
* Fixed `compas_ghpython.artists.VolMeshArtist.draw` and `compas_ghpython.artists.VolMeshArtist.draw_cells`.
5353
* Fixed `compas_rhino.artists.VolMeshArtist.draw` and `compas_rhino.artists.VolMeshArtist.draw_cells`.
54+
* Improved error messages when artist instance cannot be created.
5455

5556
### Removed
5657

src/compas/artists/artist.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ def _get_artist_cls(data, **kwargs):
4545
else:
4646
Artist.CONTEXT = identify_context()
4747

48+
if Artist.CONTEXT is None:
49+
error_message = 'No context defined.'
50+
error_message += '\n\nThis usually means that the script that you are running requires'
51+
error_message += '\na CAD environment but it is being ran as a standalone script'
52+
error_message += '\n(ie. from the command line or code editor).'
53+
raise Exception(error_message)
54+
4855
dtype = type(data)
4956
cls = None
5057

@@ -89,6 +96,10 @@ def __new__(cls, *args, **kwargs):
8996
if not Artist.__ARTISTS_REGISTERED:
9097
register_artists()
9198
Artist.__ARTISTS_REGISTERED = True
99+
100+
if not args or len(args) < 1 or args[0] is None:
101+
raise ValueError('Cannot create an artist for `None`. Please ensure you pass a instance of a supported class.')
102+
92103
cls = _get_artist_cls(args[0], **kwargs)
93104
PluginValidator.ensure_implementations(cls)
94105
return super(Artist, cls).__new__(cls)

0 commit comments

Comments
 (0)