Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upadd more informative error messages to common errors #52
Conversation
during upload of exercises
| @@ -6,7 +6,7 @@ | |||
| ) | |||
| from playhouse.migrate import PostgresqlMigrator, SqliteMigrator # noqa: I201 | |||
|
|
|||
| DB_NAME = os.getenv('DB_NAME', 'lms') | |||
| DB_NAME = os.getenv('DB_NAME', 'db') | |||
This comment has been minimized.
This comment has been minimized.
| _header_parts = header.split() | ||
| if len(_header_parts) < 2: | ||
| err = ( | ||
| f'invalid "{_UPLOAD_KEYWORD}" - got "{header}" - ' |
This comment has been minimized.
This comment has been minimized.
| _MATCHER_THRESHOLD = 0.7 | ||
|
|
||
|
|
||
| def get_similarity(header: str) -> Tuple[str, str]: |
This comment has been minimized.
This comment has been minimized.
|
|
||
|
|
||
| def get_similarity(header: str) -> Tuple[str, str]: | ||
| if not header: |
This comment has been minimized.
This comment has been minimized.
yammesicka
Apr 13, 2020
Member
Special cases aren't special enough to break the rules (if len < 2 is enough)
| @@ -314,9 +318,12 @@ def upload(): | |||
| identical_tests_tasks.solve_solution_with_identical_code.apply_async( | |||
| args=(solution.id,)) | |||
| matches.add(exercise_id) | |||
| if not matches: | |||
| errors.append("no # Upload <exercise num> headers found!") | |||
This comment has been minimized.
This comment has been minimized.
| return jsonify({ | ||
| 'exercise_matches': list(matches), | ||
| 'exercise_misses': list(misses), | ||
| 'errors': errors |
This comment has been minimized.
This comment has been minimized.
| ) -> Iterator[Tuple[str, str]]: | ||
| return filter(lambda x: x[0], map(get_exercise, (c for c in cells))) | ||
| return filter(lambda x: x[1], map(get_exercise, (c for c in cells))) |
This comment has been minimized.
This comment has been minimized.
| @@ -17,19 +41,25 @@ def get_code_cells(notebook_data: Notebook) -> Iterator[Cell]: | |||
|
|
|||
|
|
|||
| def get_exercise(cell: Cell) -> Tuple[str, str]: | |||
| # return exercise_id, exercise_code for matched exercises | |||
| # return error message in second argument | |||
| # if nothing found return both empty | |||
| code: List[str] = cell.get('source', []) | |||
This comment has been minimized.
This comment has been minimized.
yammesicka
Apr 13, 2020
Member
Maybe add itertools.dropwhile(lambda line: line.strip() == '', code)?
| _upload_header = _header_parts[0].lower() | ||
| s_matcher = difflib.SequenceMatcher(None, _upload_header, _UPLOAD_KEYWORD.lower()) | ||
| typo_msg = ( | ||
| f"You have a typo in {header} - " |
This comment has been minimized.
This comment has been minimized.
yammesicka
Apr 13, 2020
Member
It's better to leave the strings to the frontend. Maybe we should create enum file somewhere(?)

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

itraviv commentedApr 11, 2020
during upload of exercises