nix icon indicating copy to clipboard operation
nix copied to clipboard

Exceptions: need cleanup

Open gicmo opened this issue 9 years ago • 10 comments

In quite a few places (~80) we use std::runtime_error. We should find more specific errors so clients can react more specifically if they want.

gicmo avatar Sep 25 '14 09:09 gicmo

Agreed. Maybe we should collect a list of different error types here in this issue discussion?

stoewer avatar Sep 25 '14 09:09 stoewer

@stoewer Yes that would be a good idea.

gicmo avatar Sep 25 '14 09:09 gicmo

List is down to ~60.

gicmo avatar Jan 23 '15 12:01 gicmo

While working on issue #462 I discovered what we have quite a few very specific exception classes, like IncompatibleDimensions, UnsortedTicks that are used only in one or two places and might just be general std::invalid_argument exceptions with the appropriate error text. Same goes for EmptyString, DuplicateName and InvalidName which could all be InvalidName or InvalidIdentifier (or again just std::invalid_argument).

Additionally MissingAttr is thrown in cases when a file is invalid, e.g. a RangeDimension without tick attribute is present. I am thinking that throwing a exception into the API users face is maybe not the right thing todo here, but just recover as good as it is possible (empty array of ticks) and leave the rest to the file validation API.

gicmo avatar Feb 05 '15 15:02 gicmo

I'm not sure about the exceptions. The "fine-grained" exception classes allow us to provide more or less meaningful messages on the nixpy side once the exceptions, for whatever reason, loose their message as was reported by Ajay some time ago. On the other hand I agree with the desire to reduce the amount of different types.

jgrewe avatar Feb 07 '15 13:02 jgrewe

@jgrewe That exception messages were lost is very likely due to bug #462 (I have added some more detailed what was going on). We should check if the messages are indeed not empty anymore with this fix.

gicmo avatar Feb 07 '15 13:02 gicmo

@gicmo Ah, cool, makes sense. I will check this on the python side. We could then simplify the exceptions on the nix side and also clean up the exception wrapper.

jgrewe avatar Feb 07 '15 13:02 jgrewe

I will clean this up and also replace the runtime-errors.

jgrewe avatar Feb 09 '15 10:02 jgrewe

TODO

  • replace runtime errors with proper exceptions
  • separate into logic_errors and _runtime_error, i.e. those in which the user violated the program logic and could do better and those that are hard to predict from the program's point of view
  • remove where in exceptions and replace with an option of get a backtrace
  • error handling in the front-end objects, where applicable e.g. check for name constraints, etc.

jgrewe avatar Jul 22 '15 15:07 jgrewe

In several entities (e.g. Block) we require certain information to be non-empty, unique and what not. During the file_backend implementationf I noticed that the checks are not consistent, complete or even rely on throwing hdf5 exceptions. In fact we could and, imho, should, do all these checks on the front-end entities. Opinions on this?

jgrewe avatar Aug 15 '15 15:08 jgrewe