Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the error message when inserting two of the same ElementGroupsMembers #7299

Open
nick4598 opened this issue Oct 28, 2024 · 1 comment · May be fixed by #7308 or iTwin/imodel-native#905
Open
Assignees

Comments

@nick4598
Copy link
Contributor

nick4598 commented Oct 28, 2024

I believe if you had an iModel with atleast two elements you could call iModel.relationships.insertInstance with the same props twice and get the error message: "Error: sql error".
If one were to enable SQLite logging with Logger.setLevel(NativeLoggerCategory.SQLite, LogLevel.Error);

You would in addition to Error: sql error, also see

Error | SQLite | rc=2067, abort at 27 in [INSERT INTO [bis_ElementRefersToElements] ([Id],[ps1],[SourceId],[TargetId],ECClassId) VALUES (:_ecdb_ecsqlparam_ix1_col1,:_ecdb_ecsqlparam_ix2_col1,:_ecdb_ecsqlparam_ix3_col1,:_ecdb_ecsqlparam

A search of "sqlite 2067" leads you to https://www.sqlite.org/rescode.html#constraint_unique. A user should not have to enable SQLite logging in order to know that they got a unique constraint error.

My suggestion is to start off with a test in core/backend which produces the error message "Error: sql error"

Where the error occurs in imodel-native code

@DanRod1999
Copy link
Contributor

DanRod1999 commented Nov 4, 2024

Message from Affan when asked about throwSqlError():
"We have really not very good error propagation. We return DbResult from most function since underlaying sql return that but we also return BE_SQLITE_ERROR in our own validation logic.

so people have to look up log if any to find what went wrong since we log some error message but not in all cases

a better way to do this is to use throw in cpp code

closer to where the error happened"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants