From 25f785ea7dba2dc3ff7d3c5641e00033f17a2270 Mon Sep 17 00:00:00 2001 From: Rick Hennigan Date: Tue, 21 Jan 2025 14:57:31 -0500 Subject: [PATCH] Bugfix: Add error handling for unreachable cloud in snippet downloading --- Source/Chatbook/Common.wl | 2 +- Source/Chatbook/PromptGenerators/RelatedDocumentation.wl | 4 +++- Source/Chatbook/SendChat.wl | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Chatbook/Common.wl b/Source/Chatbook/Common.wl index 3a4deb25..5beb8a4a 100644 --- a/Source/Chatbook/Common.wl +++ b/Source/Chatbook/Common.wl @@ -631,7 +631,7 @@ catchMine // endDefinition; (* ::Subsection::Closed:: *) (*throwTop*) throwTop // beginDefinition; -throwTop[ expr_ ] /; $catching := Throw[ Unevaluated @ expr, $catchTopTag ]; +throwTop[ expr_ ] := If[ TrueQ @ $catching, Throw[ Unevaluated @ expr, $catchTopTag ], expr ]; throwTop // endDefinition; (* ::**************************************************************************************************************:: *) diff --git a/Source/Chatbook/PromptGenerators/RelatedDocumentation.wl b/Source/Chatbook/PromptGenerators/RelatedDocumentation.wl index 3575f0cf..9a03cb17 100644 --- a/Source/Chatbook/PromptGenerators/RelatedDocumentation.wl +++ b/Source/Chatbook/PromptGenerators/RelatedDocumentation.wl @@ -1018,7 +1018,9 @@ processDocumentationSnippetResult[ base_String, as_Association ] := processDocumentationSnippetResult[ base_String, as_, bytes_ByteArray, 200 ] := processDocumentationSnippetResult[ base, as, Quiet @ Developer`ReadWXFByteArray @ bytes ]; -processDocumentationSnippetResult[ base_String, as_Association, bytes_, code: Except[ 200, _Integer ] ] := +(* A 401/403 means we're missing a file in the snippet deployment or it has the wrong permissions, + so it should trigger an internal failure, otherwise just issue a generic cloud download failure. *) +processDocumentationSnippetResult[ base_String, as_Association, bytes_, code: Except[ 401|403 ] ] := throwFailureToChatOutput @ Failure[ "CloudDownloadError", <| diff --git a/Source/Chatbook/SendChat.wl b/Source/Chatbook/SendChat.wl index 29efd12a..6d150506 100644 --- a/Source/Chatbook/SendChat.wl +++ b/Source/Chatbook/SendChat.wl @@ -2594,7 +2594,7 @@ throwFailureToChatOutput[ task_, cell_CellObject, failure_ ] := ( ] ); -throwFailureToChatOutput[ task_, None, failure_Failure ] := ( +throwFailureToChatOutput[ task_, _, failure_Failure ] := ( Quiet @ TaskRemove @ task; throwTop @ failure );