Skip to content

Commit 0f9b3ff

Browse files
committed
added custom exception
1 parent d483ce8 commit 0f9b3ff

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
* Added `faces_where`, `faces_where_predicate`, `cells_where`, `cells_where_predicate` to `compas.datastructures.HalfFace`.
2121
* Added `VolMeshArtist` to registered Blender artists.
2222
* Added `3.1` to supported versions for Blender installer.
23+
* Added `compas.artist.NoArtistContextError`.
2324

2425
### Changed
2526

src/compas/artists/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
:nosignatures:
4040
4141
DataArtistNotRegistered
42+
NoArtistContextError
4243
4344
4445
Pluggables
@@ -58,6 +59,7 @@
5859
from __future__ import division
5960

6061
from .exceptions import DataArtistNotRegistered
62+
from .exceptions import NoArtistContextError
6163
from .artist import Artist
6264
from .curveartist import CurveArtist
6365
from .meshartist import MeshArtist
@@ -77,6 +79,7 @@
7779

7880
__all__ = [
7981
'DataArtistNotRegistered',
82+
'NoArtistContextError',
8083
'Artist',
8184
'CurveArtist',
8285
'MeshArtist',

src/compas/artists/artist.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from collections import defaultdict
88

99
import compas
10-
from compas.artists import DataArtistNotRegistered
11-
from compas.plugins import pluggable
10+
from compas.artists.exceptions import DataArtistNotRegistered
11+
from compas.artists.exceptions import NoArtistContextError
1212
from compas.plugins import PluginValidator
13+
from compas.plugins import pluggable
1314

1415
from .colordict import DescriptorProtocol
1516

@@ -46,11 +47,7 @@ def _get_artist_cls(data, **kwargs):
4647
Artist.CONTEXT = identify_context()
4748

4849
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)
50+
raise NoArtistContextError()
5451

5552
dtype = type(data)
5653
cls = None

src/compas/artists/exceptions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@
55

66
class DataArtistNotRegistered(Exception):
77
"""Exception that is raised when no artist is registered for a given data type."""
8+
9+
class NoArtistContextError(Exception):
10+
"""Exception that is raised when no artist context is assigned is registered for a given data type."""
11+
def __init__(self):
12+
error_message = "No context defined."
13+
error_message += "\n\nThis usually means that the script that you are running requires"
14+
error_message += "\na CAD environment but it is being ran as a standalone script"
15+
error_message += "\n(ie. from the command line or code editor)."
16+
super(NoArtistContextError, self).__init__(error_message)

0 commit comments

Comments
 (0)