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

feature/display error message #1192

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class FileStatus extends HTMLElement {
);
const responseObj = await response.json();
this.textContent = responseObj.status;
this.dataset.status = responseObj.status.toLowerCase();

if (responseObj.status.toLowerCase() === "complete") {
const evt = new CustomEvent("doc-complete", {
Expand Down
16 changes: 14 additions & 2 deletions django_app/frontend/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,26 @@ upload-button {
.rb-docs:has(.iai-doc-list__item) .rb-docs__show-if-no-docs {
display: none;
}
.rb-docs__upload-error {
align-items: center;
display: none;
font-size: 0.875rem;
gap: 0.75rem;
line-height: 1.4;
}
.rb-docs__upload-error svg {
color: var(--iai-product-colour);
}
.rb-docs:has(file-status[data-status*="error"]) .rb-docs__upload-error {
display: flex;
}

/* Chats Page - to come after i.AI Design System */
@import "./chat-styles.scss";

@import "./profile-overlay-styles.scss";


/* To move to i.AI design system */
.iai-chat-bubbles__sources-link:visited {
color: var(--iai-product-colour, var(--iai-colour-brand));
}
}
18 changes: 14 additions & 4 deletions django_app/redbox_app/redbox_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,20 @@ def unique_name(self) -> str:
return self.original_file.name

def get_status_text(self) -> str:
return next(
(status[1] for status in File.Status.choices if self.status == status[0]),
"Unknown",
)
permanent_error = "Error"
temporary_error = "Error, please try again"
if self.ingest_error:
temporary_error_substrings = [
"ConnectionError",
"RateLimitError",
"ConnectTimeout",
"openai.InternalServerError",
]
for substring in temporary_error_substrings:
if substring in self.ingest_error:
return temporary_error
return permanent_error
return dict(File.Status.choices).get(self.status, permanent_error)

@property
def expires_at(self) -> datetime:
Expand Down
7 changes: 1 addition & 6 deletions django_app/redbox_app/redbox_core/views/document_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def get(self, request: HttpRequest) -> HttpResponse:
@method_decorator(login_required)
def post(self, request: HttpRequest) -> HttpResponse:
errors: MutableSequence[str] = []
ingest_errors: MutableSequence[str] = []

uploaded_files: MutableSequence[UploadedFile] = request.FILES.getlist("uploadDocs")

Expand All @@ -89,11 +88,7 @@ def post(self, request: HttpRequest) -> HttpResponse:
if not errors:
for uploaded_file in uploaded_files:
# ingest errors are handled differently, as the other documents have started uploading by this point
ingest_error = self.ingest_file(uploaded_file, request.user)
if ingest_error:
ingest_errors.append(f"{uploaded_file.file_name}: {ingest_error[0]}")

request.session["ingest_errors"] = ingest_errors
request.session["ingest_errors"] = self.ingest_file(uploaded_file, request.user)
return redirect(reverse("documents"))

return self.build_response(request, errors)
Expand Down
6 changes: 6 additions & 0 deletions django_app/redbox_app/templates/documents.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ <h2 class="govuk-heading-m govuk-!-margin-top-7">Processing</h2>
docs = processing_files,
type = "processing"
) }}
<div class="rb-docs__upload-error">
<svg width="32" height="32" viewBox="0 0 18 18" fill="none" focusable="false" aria-hidden="true">
<path d="M7.875 10.125H10.125V4.5H7.875V10.125ZM10.125 12.375C10.125 11.7529 9.62212 11.25 9 11.25C8.37788 11.25 7.875 11.7529 7.875 12.375C7.875 12.9971 8.37788 13.5 9 13.5C9.62212 13.5 10.125 12.9971 10.125 12.375ZM18 9C18 4.02863 13.9714 0 9 0C4.02863 0 0 4.02863 0 9C0 13.9714 4.02863 18 9 18C13.9714 18 18 13.9714 18 9ZM15.75 9C15.75 10.8034 15.0469 12.4976 13.7745 13.7745C12.4976 15.0469 10.8034 15.75 9 15.75C7.19662 15.75 5.50238 15.0469 4.2255 13.7745C2.95312 12.4976 2.25 10.8034 2.25 9C2.25 7.19662 2.95312 5.50238 4.2255 4.2255C5.50238 2.95312 7.19662 2.25 9 2.25C10.8034 2.25 12.4976 2.95312 13.7745 4.2255C15.0469 5.50238 15.75 7.19662 15.75 9Z" fill="currentColor"/>
</svg>
<p class="govuk-!-margin-0">You have documents that failed to process. Please try again, and if the problem persists contact <a class="govuk-link" href="mailto:">redbox-support@cabinetoffice.gov.uk</a> with details.</p>
</div>
</div>

<h2 class="govuk-visually-hidden">General actions</h2>
Expand Down
2 changes: 1 addition & 1 deletion django_app/redbox_app/templates/macros/iai-doc-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{% if type == "complete" %}
{{ doc.get_status_text() }}
{% else %}
<file-status data-id="{{ doc.id }}">{{ doc.get_status_text() }}</file-status>
<file-status data-id="{{ doc.id }}" data-status="{{ doc.get_status_text() }}">{{ doc.get_status_text() }}</file-status>
{% endif %}
</td>
<td class="iai-doc-list__cell--actions">
Expand Down
20 changes: 11 additions & 9 deletions redbox-core/redbox/loader/ingester.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def create_alias(alias: str):
es.indices.put_alias(index=chunk_index_name, name=alias)


def ingest_file(file_name: str, es_index_name: str = alias) -> str | None:
def _ingest_file(file_name: str, es_index_name: str = alias):
logging.info("Ingesting file: %s", file_name)

es = env.elasticsearch_client()
Expand Down Expand Up @@ -96,15 +96,17 @@ def ingest_file(file_name: str, es_index_name: str = alias) -> str | None:
env=env,
)

new_ids = RunnableParallel({"normal": chunk_ingest_chain, "largest": large_chunk_ingest_chain}).invoke(file_name)
logging.info(
"File: %s %s chunks ingested",
file_name,
{k: len(v) for k, v in new_ids.items()},
)


def ingest_file(file_name: str, es_index_name: str = alias) -> str | None:
try:
new_ids = RunnableParallel({"normal": chunk_ingest_chain, "largest": large_chunk_ingest_chain}).invoke(
file_name
)
logging.info(
"File: %s %s chunks ingested",
file_name,
{k: len(v) for k, v in new_ids.items()},
)
_ingest_file(file_name, es_index_name)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we want to capture all errors not just those from large_chunk_ingest_chain

except Exception as e:
logging.exception("Error while processing file [%s]", file_name)
return f"{type(e)}: {e.args[0]}"
Loading