Lets say I am making a custom fixed-sized array type in Python. This array supports setting a range of values using a slice and an iterable.
a = Array("1234") a[1:3] = "to" a == Array("1to4")
Because the array is fixed in size, you cannot do what you can with lists where you set a slice using an iterable of larger or smaller size, which changes the size of the list; instead you should raise an exception.
a = Array("1234") a[:] = "thisistoobig" # ValueError
The question is, how much information should go in the exception’s error message? Should it include the value that caused the failure? Should it include only the length of the value? What about the length of slice you are trying to set?
The same question could be asked in general, what happens when you index out of bounds? Python’s error message for indexing a list out-of-bounds is
"list index out of bounds" with no mention of the index value that caused the failure. Is there a general philosophy of “just use a debugger to find the failing value”? Is there some other consideration as to why it couldn’t or shouldn’t be more informative? Or is it just all over the place and there is no recommended best practice here, or in the main codebase?