FirebirdSQL / NETProvider

Firebird ADO.NET Data Provider
https://www.firebirdsql.org/en/net-provider/
Other
152 stars 62 forks source link

ErrorCode in IscException as an enum #1145

Closed ranger-turtle closed 6 months ago

ranger-turtle commented 6 months ago

I have noticed that ErrorCode property in IscException can be changed to enum to make referring to the constants more readable. However, I am not sure it is a good idea, since it may break systems depending on .NET Provider too much.

I am going to refer to this doc: https://www.firebirdsql.org/pdfrefdocs/Firebird-2.1-ErrorCodes.pdf

cincuranet commented 6 months ago

IscException is internal. And FbException derives from DbException where ErrorCode is defined as int anyway.

ranger-turtle commented 6 months ago

IscException is internal. And FbException derives from DbException where ErrorCode is defined as int anyway.

Thank you for answer but end-programmers would use ErrorCode from FbException in catch (Exception) when (condition) section anyway and it would be more pleasant to read if it would be at least compared to enum.

By the way, I guess I have a better idea - I would just make the enum itself, and leave ErrorType unchanged in all classes, including FbException. End-programmer can just cast the value to int in comparisons. What do you think?

cincuranet commented 6 months ago

Thank you for answer but end-programmers would use ErrorCode from FbException in catch (Exception) when (condition) section anyway and it would be more pleasant to read if it would be at least compared to enum.

Sure. But you would have to change it in DbException in the first place.

By the way, I guess I have a better idea - I would just make the enum itself, and leave ErrorType unchanged in all classes, including FbException. End-programmer can just cast the value to int in comparisons. What do you think?

I think the best solution would be to have something like FbErrorCodes class with bunch of fields and allow simply to compare ErrorCode to known field. That would give you the textual representation of error code as well as simplicity of using it. Something like catch (FbException ex) when (ex.ErrorCode == FbErrorCodes.FooBar).

ranger-turtle commented 6 months ago

I think the best solution would be to have something like FbErrorCodes class with bunch of fields and allow simply to compare ErrorCode to known field. That would give you the textual representation of error code as well as simplicity of using it. Something like catch (FbException ex) when (ex.ErrorCode == FbErrorCodes.FooBar).

Fairly good idea but instead of bunch of fields, I would give one field of enum type.

cincuranet commented 6 months ago

That would require explicit cast to enum.

cincuranet commented 6 months ago

https://github.com/FirebirdSQL/NETProvider/issues/1148