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

tweak(adminPanel): RN-1255: Bulk error handling for importing survey questions #5641

Merged
merged 21 commits into from
Jul 18, 2024

Conversation

alexd-bes
Copy link
Contributor

Issue RN-1255: Bulk error handling for importing survey questions

Changes:

  • Added handling on the admin panel frontend for multi errors
  • Updated import logic to bulk validate all questions before throwing an error
  • Update error classes to handle passing details around

Screenshots:

@@ -10,7 +10,7 @@ import { verifyResponseStatus, stringifyQuery } from '@tupaia/utils';

import { logout } from '../authentication';

const FETCH_TIMEOUT = 45 * 1000; // 45 seconds in milliseconds
const FETCH_TIMEOUT = 120 * 1000; // 45 seconds in milliseconds
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because a survey import could actually take more than 45 seconds now that it doesn't 'fail fast'

message: {
paddingBlock: '0.5rem',
},
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Overriding styling in ui-components

Copy link
Collaborator

@rohan-bes rohan-bes left a comment

Choose a reason for hiding this comment

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

Looks and feels good!

Definitely keen for the couple comments I made to be addressed since I think they catch genuine bugs, but pre-approving 👍

Comment on lines 170 to 173
} catch (e) {
errors.push(e);
continue;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I'd recommend extending this try/catch all the way down to the bottom of the rows loop. That way it's just a bit more guaranteed that we catch all errors, and it's more future-proof to new validation being added.

For instance one that isn't currently doesn't catch an error that might occur when we call processOptionSetName on line 213.

@@ -20,7 +20,7 @@ const palette = {
},
error: {
main: COLORS.RED,
light: COLORS.LIGHT_RED,
light: `${COLORS.LIGHT_RED}1A`, // 10% opacity
Copy link
Collaborator

Choose a reason for hiding this comment

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

🧙

Comment on lines 119 to 124
const constructImportValidationError = (message, field, { details }) => {
return {
message: new ImportValidationError(message, excelRowNumber, field).message,
details,
};
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const constructImportValidationError = (message, field, { details }) => {
return {
message: new ImportValidationError(message, excelRowNumber, field).message,
details,
};
};
const constructImportValidationError = (message, field, { details }) =>
new ImportValidationError(message, excelRowNumber, field, undefined, details);

I think we still want this function to be returning an error, as when we pass it into ObjectValidator that's what it's expected to do. We can convert the errors into the wrapped objects latter when we create the MultiValidationError

Comment on lines 287 to 289
if (errors.length > 0) {
throw new MultiValidationError('Errors occurred while importing questions', errors);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (errors.length > 0) {
throw new MultiValidationError('Errors occurred while importing questions', errors);
}
if (errors.length > 0) {
throw new MultiValidationError(
'Errors occurred while importing questions',
errors.map(({ message, extraFields }) => ({
message,
extraFields,
})),
);
}

Assuming we've done the above comment to switch errors to be a list of Error instances

@alexd-bes alexd-bes merged commit 99082f6 into dev Jul 18, 2024
44 checks passed
@alexd-bes alexd-bes deleted the rn-1255-error-handling-surveys branch July 18, 2024 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants