• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / DataSpecification / 4563269470

pending completion
4563269470

push

github

GitHub
Merge pull request #135 from SpiNNakerManchester/doc-polish

342 of 415 branches covered (82.41%)

Branch coverage included in aggregate %.

94 of 94 new or added lines in 5 files covered. (100.0%)

1420 of 1517 relevant lines covered (93.61%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.27
/data_specification/exceptions.py
1
# Copyright (c) 2014 The University of Manchester
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     https://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15

16
class DataSpecificationException(Exception):
1✔
17
    """
18
    A general purpose exception indicating that something went
19
    wrong when interacting with a Data Specification.
20
    """
21

22

23
class DataUndefinedWriterException(Exception):
1✔
24
    """
25
    An exception that indicates that the file data writer has not been
26
    initialised.
27
    """
28

29

30
class RegionInUseException(DataSpecificationException):
1✔
31
    """
32
    An exception that indicates that a region has already been allocated.
33
    """
34

35
    def __init__(self, region, label=None):
1✔
36
        """
37
        :param int region: The region that was already allocated
38
        :param label: What label is known for the region
39
        :type label: str or None
40
        """
41
        if label is None:
1!
42
            msg = f"Region {region:d} was already allocated"
1✔
43
        else:
44
            msg = f"Region {region:d} ({label}) was already allocated"
×
45
        super().__init__(msg)
1✔
46

47

48
class StructureInUseException(DataSpecificationException):
1✔
49
    """
50
    An exception that indicates that a structure has already been defined.
51
    """
52

53
    def __init__(self, structure):
1✔
54
        """
55
        :param int structure: The structure that was already allocated
56
        """
57
        super().__init__(f"Structure {structure} was already allocated")
1✔
58

59

60
class RegionUnfilledException(DataSpecificationException):
1✔
61
    """
62
    An exception that indicates that a memory region is being used
63
    that was originally requested to be unfilled.
64
    """
65

66
    def __init__(self, region, command):
1✔
67
        """
68
        :param int region: The region that was requested as unfilled
69
        :param str command: The command being executed
70
        """
71
        super().__init__(
1✔
72
            f"Region {region} was requested unfilled, but command {command} "
73
            "requests its use")
74

75

76
class NoRegionSelectedException(DataSpecificationException):
1✔
77
    """
78
    An exception that indicates that a memory region has not been selected.
79
    """
80

81
    def __init__(self, command):
1✔
82
        """
83
        :param str command: The command being executed
84
        """
85
        super().__init__(
1✔
86
            f"Command {command} tries to operate on an unspecified "
87
            "memory region")
88

89

90
class RegionExhaustedException(DataSpecificationException):
1✔
91
    """
92
    An exception that indicates that a region has run out of memory
93
    whilst some data is being written.
94
    """
95

96
    def __init__(self, region, region_size, allocated_size, command):
1✔
97
        """
98
        :param int region: The region that was being written to
99
        :param int region_size: The originally requested size of the region
100
            that has run out of space, in bytes
101
        :param int allocated_size: The amount of the originally requested
102
            space that has already been allocated, in bytes
103
        :param str command: The command being executed
104
        """
105
        super().__init__(
×
106
            f"Region {region} with size {region_size} ran out of allocated "
107
            f"memory (space already occupied {allocated_size}) during "
108
            f"command {command}")
109

110

111
class RegionOutOfBoundsException(DataSpecificationException):
1✔
112
    """
113
    An exception that indicates that an offset into a region is out
114
    of bounds for that region.
115
    """
116

117
    def __init__(self, region, region_size, requested_offset, command):
1✔
118
        """
119
        :param int region: The region that was being offset into
120
        :param int region_size:
121
            The originally requested size of the region in question, in bytes
122
        :param int requested_offset: The offset being requested, in bytes
123
        :param str command: The command being executed
124
        """
125
        super().__init__(
×
126
            f"Requesting offset {requested_offset} into region {region} "
127
            f"with size {region_size} during command {command}")
128

129

130
class ParameterOutOfBoundsException(DataSpecificationException):
1✔
131
    """
132
    An exception that indicates that a parameter value was outside of the
133
    allowed bounds.
134
    """
135

136
    def __init__(self, parameter, value, range_min, range_max, command):
1✔
137
        """
138
        :param str parameter: The parameter that is out of bounds
139
        :param value: The value specified
140
        :type value: float or int
141
        :param range_min: The minimum allowed value
142
        :type range_min: float or int
143
        :param range_max: The maximum allowed value
144
        :type range_max: float or int
145
        :param str command: The command being executed
146
        """
147
        # pylint: disable=too-many-arguments
148
        super().__init__(
1✔
149
            f"Requesting value {value} for parameter {parameter} whose "
150
            f"allowed range is from {range_min} to {range_max} during "
151
            f"command {command}")
152

153

154
class NotAllocatedException(DataSpecificationException):
1✔
155
    """
156
    An exception that indicates that an item is being used
157
    that has not been allocated.
158
    """
159

160
    def __init__(self, item_type, item_id, command):
1✔
161
        """
162
        :param str item_type: The type of the item being used
163
        :param int item_id: The ID of the item being used
164
        :param str command: The command being executed
165
        """
166
        super().__init__(
1✔
167
            f"Using unallocated item with type {item_type} and ID {item_id} "
168
            f"during command {command}")
169

170

171
class NoMoreException(DataSpecificationException):
1✔
172
    """
173
    An exception that indicates that there is no more space for the
174
    requested item.
175
    """
176

177
    def __init__(self, space_available, space_required, region):
1✔
178
        """
179
        :param int space_available: The space available in the region
180
        :param int space_required: The space requested by the write command
181
        """
182
        super().__init__(
1✔
183
            "Space unavailable to write all the elements requested by the "
184
            f"write operation. Space available: {space_available}; space "
185
            f"requested: {space_required} for region {region}.")
186

187

188
class FunctionInUseException(DataSpecificationException):
1✔
189
    """
190
    An exception that indicates that a function is already defined.
191
    """
192

193
    def __init__(self, function_id):
1✔
194
        """
195
        :param int function_id: The ID of the function
196
        """
197
        super().__init__(f"Function {function_id} is already defined")
1✔
198

199

200
class RNGInUseException(DataSpecificationException):
1✔
201
    """
202
    An exception that indicates that a random number generator is already
203
    defined.
204
    """
205

206
    def __init__(self, rng_id):
1✔
207
        """
208
        :param int rng_id: The ID of the rng
209
        """
210
        super().__init__(
1✔
211
            f"Random number generator {rng_id} is already defined")
212

213

214
class RandomNumberDistributionInUseException(DataSpecificationException):
1✔
215
    """
216
    An exception that indicates that a random number distribution is already
217
    defined.
218
    """
219

220
    def __init__(self, rng_id):
1✔
221
        """
222
        :param int rng_id: The ID of the random number distribution
223
        """
224
        super().__init__(
1✔
225
            f"Random number distribution {rng_id} is already defined")
226

227

228
class WrongParameterNumberException(DataSpecificationException):
1✔
229
    """
230
    An exception that indicates that a function has been called with a
231
    wrong number of parameters.
232
    """
233

234
    def __init__(self, function_id, no_of_parameters_required, parameters):
1✔
235
        """
236
        :param int function_id: The ID of the function
237
        :param list parameters: The parameters used in the function call
238
        :param int no_of_parameters_required:
239
            The number of parameters required by the function
240
        """
241
        super().__init__(
1✔
242
            f"Function {function_id} that requires {no_of_parameters_required}"
243
            " parameters has been called with the following "
244
            f"parameters: {parameters}")
245

246

247
class DuplicateParameterException(DataSpecificationException):
1✔
248
    """
249
    An exception that indicates that a command has been called with a
250
    duplicate parameter, which shouldn't be allowed.
251
    """
252

253
    def __init__(self, command, parameters):
1✔
254
        """
255
        :param int command: The command called with duplicate parameters
256
        :param list parameters: The parameters used to call the function
257
        """
258
        super().__init__(
1✔
259
            f"The command {command} has been called with duplicate "
260
            f"parameters: {repr(parameters)}")
261

262

263
class NestedFunctionException(DataSpecificationException):
1✔
264
    """
265
    An exception that indicates that a function is being defined within
266
    the context of another function definition.
267
    """
268

269
    def __init__(self):
1✔
270
        super().__init__("Nested function definition not supported")
×
271

272

273
class TypeMismatchException(DataSpecificationException):
1✔
274
    """
275
    An exception that indicates that a type mismatch has occurred.
276
    """
277

278
    def __init__(self, command):
1✔
279
        """
280
        :param str command: The command that generated the exception
281
        """
282
        super().__init__(
1✔
283
            f"A type mismatch has occurred during command {command}")
284

285

286
class UnknownTypeException(DataSpecificationException):
1✔
287
    """
288
    An exception that indicates that the value of the requested type
289
    is unknown.
290
    """
291

292
    def __init__(self, type_id, command):
1✔
293
        """
294
        :param int type_id: The ID of the requested type
295
        :param str command: The command being executed
296
        """
297
        super().__init__(
×
298
            f"Unknown ID value {type_id} for data type during "
299
            f"command {command}")
300

301

302
class UnknownTypeLengthException(DataSpecificationException):
1✔
303
    """
304
    An exception that indicates that the value of the requested type
305
    is unknown.
306
    """
307

308
    def __init__(self, data_length, command):
1✔
309
        """
310
        :param int data_length: the length of the requested type
311
        :param str command: The command being executed
312
        """
313
        super().__init__(
×
314
            f"Unknown data length {data_length} during command {command}")
315

316

317
class InvalidSizeException(DataSpecificationException):
1✔
318
    """
319
    An exception that indicates that the size of the requested type is invalid.
320
    """
321

322
    def __init__(self, type_name, type_size, command):
1✔
323
        """
324
        :param str type_name: The name of the requested type
325
        :param int type_size: The size of the requested variable
326
        :param str command: The command being executed
327
        """
328
        super().__init__(
×
329
            f"Invalid size {type_size} of the requested type {type_name} "
330
            f"during command {command}")
331

332

333
class InvalidCommandException(DataSpecificationException):
1✔
334
    """
335
    An exception that indicates that the command being requested cannot
336
    be executed at this point in the specification.
337
    """
338

339
    def __init__(self, command):
1✔
340
        """
341
        :param str command: The command being executed
342
        """
343
        super().__init__(
1✔
344
            f"The requested command {command} cannot be executed at this "
345
            "point in the specification")
346

347

348
class UnknownConditionException(DataSpecificationException):
1✔
349
    """
350
    An exception which is triggered in case the condition in an IF test
351
    does not exist in the list of possible conditions.
352
    """
353

354
    def __init__(self, condition_id, command):
1✔
355
        """
356
        :param int condition_id: ID of the condition being requested
357
        :param str command: The command being executed
358
        """
359
        super().__init__(
×
360
            f"The requested condition with ID {condition_id} does not belong "
361
            f"to the list of possible tests during command {command}")
362

363

364
class InvalidOperationException(DataSpecificationException):
1✔
365
    """
366
    An exception that indicates that the operation of the type given type
367
    is not available.
368
    """
369

370
    def __init__(self, operation_type, requested_operation_id, command):
1✔
371
        """
372
        :param str operation_type:
373
            The type of operation requested (i.e. arithmetic or logic)
374
        :param int requested_operation_id: The ID of the requested operation
375
        :param str command: The command being executed
376
        """
377
        super().__init__(
1✔
378
            f"The {operation_type} operation requested with ID "
379
            f"{requested_operation_id} does not match the possible operations "
380
            f"available during command {command}")
381

382

383
class ExecuteBreakInstruction(DataSpecificationException):
1✔
384
    """
385
    An exception which occurs when a `BREAK` instruction is found in the
386
    data specification.
387
    """
388

389
    def __init__(self, address, filename):
1✔
390
        """
391
        :param int address: address of the data specification being executed
392
            at the time of breakpoint
393
        :param str filename: file being parsed
394
        """
395
        super().__init__(
×
396
            f"Executing BREAK instruction at address {address} of "
397
            f"file {filename}")
398

399

400
class DataSpecificationSyntaxError(DataSpecificationException):
1✔
401
    """
402
    An exception which occurs when a command read from the data
403
    specification file shows an inconsistency in the binary content.
404
    """
405

406

407
class TablePointerOutOfMemoryException(DataSpecificationException):
1✔
408
    """
409
    An exception which occurs when building the table pointer as header of the
410
    data generated by the spec executor. This message is printed in case the
411
    memory available is not enough to contain the pointer table for each of
412
    the allocated regions.
413
    """
414

415
    def __init__(self, memory_available, memory_required):
1✔
416
        """
417

418
        :param int memory_available: on-chip memory available
419
        :param int memory_required: on-chip memory required to complete the
420
            execution of the specification file
421
        """
422
        super().__init__(
×
423
            f"The memory available {memory_available} is not sufficient for "
424
            "the allocated regions plus the header table "
425
            f"pointer {memory_required}")
426

427

428
class RegionNotAllocatedException(DataSpecificationException):
1✔
429
    """
430
    An exception which occurs when trying to write to an unallocated
431
    region of memory.
432
    """
433

434
    def __init__(self, region, command):
1✔
435
        """
436
        :param int region: The ID of the region that was not allocated.
437
        :param str command: The name of the command that was being handled.
438
        """
439
        super().__init__(
×
440
            f"Region {region} has not been allocated during execution of "
441
            f"command {command}")
442

443

444
class UnimplementedDSECommandError(DataSpecificationException):
1✔
445
    """
446
    An exception which occurs when trying to execute an unimplemented
447
    command.
448
    """
449

450
    def __init__(self, command):
1✔
451
        """
452
        :param str command: Command attempted to be executed by the DSE
453
        """
454
        super().__init__(
×
455
            f"Command {command} in the data specification executor has "
456
            "not yet been implemented")
457

458

459
class UnimplementedDSGCommandError(DataSpecificationException):
1✔
460
    """
461
    An exception which occurs when trying to write an unimplemented command.
462
    """
463

464
    def __init__(self, command):
1✔
465
        """
466
        :param str command: Command attempted to be generated by the DSG
467
        """
468
        super().__init__(
×
469
            f"Command {command} in the data specification generator has "
470
            "not yet been implemented")
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc