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

Cleanup panic and unwrap #1231

Merged
merged 49 commits into from Feb 1, 2023
Merged

Cleanup panic and unwrap #1231

merged 49 commits into from Feb 1, 2023

Conversation

billy1624
Copy link
Member

@billy1624 billy1624 commented Nov 16, 2022

PR Info

Changes

  • Implemented From<DbErr> for TransactionError<E>

@billy1624 billy1624 self-assigned this Nov 16, 2022
@billy1624 billy1624 marked this pull request as ready for review November 17, 2022 08:15
@billy1624
Copy link
Member Author

Please review!

src/error.rs Outdated Show resolved Hide resolved
src/database/mock.rs Outdated Show resolved Hide resolved
src/database/mock.rs Outdated Show resolved Hide resolved
@tyt2y3
Copy link
Member

tyt2y3 commented Nov 17, 2022

Looks good for what this PR changes

src/database/mock.rs Outdated Show resolved Hide resolved
src/database/mock.rs Outdated Show resolved Hide resolved
@tyt2y3
Copy link
Member

tyt2y3 commented Nov 17, 2022

This PR mostly touches the Connection and Mock API, I think there might be other places to cleanup too?

@billy1624
Copy link
Member Author

billy1624 commented Nov 17, 2022

This PR mostly touches the Connection and Mock API, I think there might be other places to cleanup too?

Hey @tyt2y3, yes, but I think we can leave them as-is:

20 results - 10 files

src/entity/active_model.rs:
  168              }
  169:             _ => panic!("The arity cannot be larger than 6"),
  170          }

  812              ActiveValue::Set(value) | ActiveValue::Unchanged(value) => value,
  813:             ActiveValue::NotSet => panic!("Cannot unwrap ActiveValue::NotSet"),
  814          }

  844              ActiveValue::Set(value) | ActiveValue::Unchanged(value) => value,
  845:             ActiveValue::NotSet => panic!("Cannot borrow ActiveValue::NotSet"),
  846          }

src/entity/base_entity.rs:
  270              } else {
  271:                 panic!("primary key arity mismatch");
  272              }

  274          if keys.next().is_some() {
  275:             panic!("primary key arity mismatch");
  276          }

  837              } else {
  838:                 panic!("primary key arity mismatch");
  839              }

  841          if keys.next().is_some() {
  842:             panic!("primary key arity mismatch");
  843          }

src/executor/cursor.rs:
  95                  .add(f(c1, v1)),
  96:             _ => panic!("column arity mismatch"),
  97          }

src/executor/execute.rs:
  48              ExecResultHolder::SqlxPostgres(_) => {
  49:                 panic!("Should not retrieve last_insert_id this way")
  50              }

  54                  if last_insert_rowid < 0 {
  55:                     panic!("negative last_insert_rowid")
  56                  } else {

src/query/combine.rs:
  49                              ColumnRef::Asterisk | ColumnRef::TableAsterisk(_) => {
  50:                                 panic!("cannot apply alias for Column with asterisk")
  51                              }

  58                                  ColumnRef::Asterisk | ColumnRef::TableAsterisk(_) => {
  59:                                     panic!("cannot apply alias for AsEnum with asterisk")
  60                                  }

  62                              _ => {
  63:                                 panic!("cannot apply alias for AsEnum with expr other than Column")
  64                              }
  65                          },
  66:                         _ => panic!("cannot apply alias for expr other than Column or AsEnum"),
  67                      };

src/query/delete.rs:
  115                  }
  116:                 ActiveValue::NotSet => panic!("PrimaryKey is not set"),
  117              }

src/query/helper.rs:
  585          }
  586:         _ => panic!("Owner key and foreign key mismatch"),
  587      }

src/query/insert.rs:
  136              } else if self.columns[idx] != av_has_val {
  137:                 panic!("columns mismatch");
  138              }

src/query/update.rs:
   99                  }
  100:                 ActiveValue::NotSet => panic!("PrimaryKey is not set"),
  101              }

src/schema/entity.rs:
  49      if matches!(backend, DbBackend::MySql | DbBackend::Sqlite) {
  50:         panic!("TypeCreateStatement is not supported in MySQL & SQLite");
  51      }

  59          ColumnType::Enum { name, variants } => (name.clone(), variants.clone()),
  60:         _ => panic!("Should be ColumnType::Enum"),
  61      };

@billy1624
Copy link
Member Author

There are too many breaking changes stapled together, which is risky. Can we avoid all breaking changes, if possible?

Sure! Check again :D

@billy1624 billy1624 requested a review from tyt2y3 January 31, 2023 15:34
src/database/mock.rs Outdated Show resolved Hide resolved
src/database/mock.rs Outdated Show resolved Hide resolved
src/driver/mock.rs Outdated Show resolved Hide resolved
src/driver/sqlx_sqlite.rs Outdated Show resolved Hide resolved
@tyt2y3
Copy link
Member

tyt2y3 commented Jan 31, 2023

This is still a LOT of changes and hopefully I did not miss a fine detail

@billy1624 billy1624 requested a review from tyt2y3 February 1, 2023 07:58
Copy link
Member

@tyt2y3 tyt2y3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tyt2y3 tyt2y3 merged commit 91c4930 into master Feb 1, 2023
@tyt2y3 tyt2y3 deleted the replace-panic branch February 1, 2023 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Replace all unwrap() with expect()
3 participants