Skip to content

Commit

Permalink
Throw a specific error if the Outline requested can't be found
Browse files Browse the repository at this point in the history
  • Loading branch information
vincode-io committed Jul 9, 2024
1 parent dd8abd6 commit badba32
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
8 changes: 6 additions & 2 deletions Zavala/AppIntents/Outline/AddOutlineTagAppIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ struct AddOutlineTagAppIntent: AppIntent, CustomIntentMigratedAppIntent, Predict
func perform() async throws -> some IntentResult {
await resume()

guard let outline = await findOutline(outline),
let tag = await outline.account?.createTag(name: tagName) else {
guard let outline = await findOutline(outline) else {
await suspend()
throw ZavalaAppIntentError.outlineNotFound
}

guard let tag = await outline.account?.createTag(name: tagName) else {
await suspend()
throw ZavalaAppIntentError.unexpectedError
}
Expand Down
2 changes: 1 addition & 1 deletion Zavala/AppIntents/Outline/EditOutlineAppIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct EditOutlineAppIntent: AppIntent, CustomIntentMigratedAppIntent, Predictab

guard let outline = await findOutline(outline) else {
await suspend()
throw ZavalaAppIntentError.unexpectedError
throw ZavalaAppIntentError.outlineNotFound
}

switch detail {
Expand Down
2 changes: 1 addition & 1 deletion Zavala/AppIntents/Outline/ExportAppIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct ExportAppIntent: AppIntent, CustomIntentMigratedAppIntent, PredictableInt

guard let outline = findOutline(outline) else {
await suspend()
throw ZavalaAppIntentError.unexpectedError
throw ZavalaAppIntentError.outlineNotFound
}

let useAltLinks = exportLinkType == .altLinks
Expand Down
3 changes: 3 additions & 0 deletions Zavala/AppIntents/ZavalaAppIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extension ZavalaAppIntent {
enum ZavalaAppIntentError: Error, CustomLocalizedStringResourceConvertible {
case unexpectedError
case outlineNotBeingViewed
case outlineNotFound
case noTagsSelected
case unavailableAccount

Expand All @@ -52,6 +53,8 @@ enum ZavalaAppIntentError: Error, CustomLocalizedStringResourceConvertible {
return "An unexpected error occurred. Please try again."
case .outlineNotBeingViewed:
return "There isn't an Outline currently being viewed."
case .outlineNotFound:
return "The requested Outline was not found."
case .noTagsSelected:
return "No Tags are currently selected."
case .unavailableAccount:
Expand Down
11 changes: 7 additions & 4 deletions Zavala/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,13 @@
"Get Current Tags" : {

},
"Get Images For Outline" : {
"Get Images for %@" : {

},
"Get Images for%@" : {
"Get Images for ${outline}" : {

},
"Get Images for${outline}" : {
"Get Images For Outline" : {

},
"Get Info" : {
Expand Down Expand Up @@ -543,7 +543,7 @@
"Get the currently viewed outline from the foremost window for Zavala." : {

},
"Gets all the images associated with the given Outline. Useful for integrating with outlines exported as Markdown." : {
"Gets all the Images associated with the given Outline. Useful for integrating with Outlines exported as Markdown." : {

},
"Gets the name of the currently selected Tags if there are any." : {
Expand Down Expand Up @@ -1097,6 +1097,9 @@
},
"The requested document could not be found. It was most likely deleted and is no longer available." : {
"comment" : "Alert Message: Document Not Found"
},
"The requested Outline was not found." : {

},
"The specified Account isn't available to be used." : {

Expand Down

0 comments on commit badba32

Please sign in to comment.