Skip to content

type mis-match corrected and add connection cleanup#5044

Open
MRGLOBIN wants to merge 3 commits intowailsapp:masterfrom
MRGLOBIN:doc-tutorial-dogsapi
Open

type mis-match corrected and add connection cleanup#5044
MRGLOBIN wants to merge 3 commits intowailsapp:masterfrom
MRGLOBIN:doc-tutorial-dogsapi

Conversation

@MRGLOBIN
Copy link

@MRGLOBIN MRGLOBIN commented Mar 12, 2026

there was a type mis-match for AllBreeds struct. the url return map[string][]string which causes application to mis-behave. also added connection close to the http request and some minor improvements.

This is change to the tutorial app

Summary by CodeRabbit

  • Documentation
    • Updated Dogs API tutorial with centralized error handling and safer HTTP response handling.
    • Improved frontend examples to use clearer promise-based async flows for loading breeds, random image, and photos.
    • Adjusted API response description to reflect a streamlined breed list format.

there was a type mis-match for AllBreeds struct. the url return
map[string][]string which causes application to mis-behave. also added
connection close to the http request and some minor imporovements.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

Changed the AllBreeds data model from a nested to a flat map, added centralized error handling and ensured HTTP responses are closed, and updated frontend tutorial examples to use block-scoped promise handling and adjusted documentation accordingly.

Changes

Cohort / File(s) Summary
Backend model & error handling
app.go
Changed AllBreeds.Message from map[string]map[string][]stringmap[string][]string; added handleError(err) and replaced direct log.Fatal(err) calls; added defer response.Body.Close() after HTTP responses.
Frontend example & async flow
web/src/App.svelte, website/docs/tutorials/dogsapi.mdx, website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx
Reformatted frontend examples to use multiline .then blocks and block-scoped state updates for GetRandomImageUrl, GetBreedList, and GetImageUrlsByBreed; no runtime behavior changes.
Documentation only
website/docs/tutorials/dogsapi.mdx, website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx
Adjusted prose and code snippet layout to reflect the model and error-handling updates; duplicated in current and versioned docs.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I nudged the maps to neat and flat,
Caught stray errors, closed each hat,
Promises lined up, tidy and true,
Docs hopped along — a fresher view,
Nibble the carrot, code anew. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description lacks critical sections from the template including linked issue reference, type of change checkbox selection, testing details, test configuration, and completion checklist. Add 'Fixes #' reference, select the appropriate type of change checkbox, include how the changes were tested with platform details, paste wails doctor output, and complete the PR checklist.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main changes: correcting a type mismatch in the AllBreeds struct and adding HTTP connection cleanup via response body closure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can customize the high-level summary generated by CodeRabbit.

Configure the reviews.high_level_summary_instructions setting to provide custom instructions for generating the high-level summary.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx (1)

87-99: ⚠️ Potential issue | 🟡 Minor

Inconsistent indentation on defer statement.

Line 90 uses spaces for indentation while the rest of the Go code uses tabs. This inconsistency appears in all three functions (GetRandomImageUrl, GetBreedList, GetImageUrlsByBreed).

Proposed fix for indentation
 func (a *App) GetRandomImageUrl() string {
 	response, err := http.Get("https://dog.ceo/api/breeds/image/random")
 	handleError(err)
-  defer response.Body.Close()
+	defer response.Body.Close()

Apply similar fix to lines 106 and 128.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx` around lines 87
- 99, The defer statements in GetRandomImageUrl, GetBreedList, and
GetImageUrlsByBreed are indented with spaces instead of tabs, causing
inconsistent indentation; edit each function (GetRandomImageUrl, GetBreedList,
GetImageUrlsByBreed) and replace the leading spaces before "defer
response.Body.Close()" with a single tab so the defer lines match the tab-based
indentation used throughout the file, and run gofmt to verify consistent
formatting.
🧹 Nitpick comments (1)
website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx (1)

143-152: ioutil package is deprecated since Go 1.16.

The tutorial uses ioutil.ReadAll which was deprecated in Go 1.16. Consider updating to use io.ReadAll instead for teaching current best practices.

Proposed fix for imports and usage

Update the import section:

 import (
 	"context"
 	"fmt"
 	"encoding/json"
-	"io/ioutil"
+	"io"
 	"log"
 	"net/http"
 	"sort"
 )

Then replace ioutil.ReadAll with io.ReadAll in the function bodies.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx` around lines
143 - 152, The code imports and uses the deprecated ioutil package (e.g.,
ioutil.ReadAll); update the imports to remove "io/ioutil" and add "io" instead,
and replace all calls to ioutil.ReadAll with io.ReadAll in the request/response
handler functions (where ReadAll is used) so the tutorial uses the modern Go
1.16+ API (ensure you update any example code comments and import list
accordingly).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx`:
- Around line 180-183: The promise callback bodies are misindented; fix
indentation inside the .then() handlers so the statements setting randomImageUrl
and showRandomPhoto are indented one level inside the arrow function for
GetRandomImageUrl(), and apply the same consistent indentation to the .then()
callback in getImageUrlsByBreed (ensure the statements inside that callback are
indented under the arrow function), preserving existing variable names
randomImageUrl and showRandomPhoto and the arrow function syntax.
- Around line 170-172: The init() function calls getBreedList().then(...), but
getBreedList does not return a promise causing a runtime TypeError; fix by
either (A) making getBreedList return the promise it creates (add a return so
getBreedList returns the fetch/async promise) so init() can use .then as
written, or (B) change init() to call getBreedList directly (e.g., await
getBreedList() inside an async init or call getBreedList() and handle the result
synchronously) and remove the .then; update either getBreedList or init
accordingly and ensure references to getBreedList and init remain consistent.

---

Outside diff comments:
In `@website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx`:
- Around line 87-99: The defer statements in GetRandomImageUrl, GetBreedList,
and GetImageUrlsByBreed are indented with spaces instead of tabs, causing
inconsistent indentation; edit each function (GetRandomImageUrl, GetBreedList,
GetImageUrlsByBreed) and replace the leading spaces before "defer
response.Body.Close()" with a single tab so the defer lines match the tab-based
indentation used throughout the file, and run gofmt to verify consistent
formatting.

---

Nitpick comments:
In `@website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx`:
- Around line 143-152: The code imports and uses the deprecated ioutil package
(e.g., ioutil.ReadAll); update the imports to remove "io/ioutil" and add "io"
instead, and replace all calls to ioutil.ReadAll with io.ReadAll in the
request/response handler functions (where ReadAll is used) so the tutorial uses
the modern Go 1.16+ API (ensure you update any example code comments and import
list accordingly).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 593cec4a-5250-41e9-9cfe-0297121520fe

📥 Commits

Reviewing files that changed from the base of the PR and between 4d0abeb and 77c2a06.

📒 Files selected for processing (2)
  • website/docs/tutorials/dogsapi.mdx
  • website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx

the GetBreedList do not return promise and populates the files
internally
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@website/docs/tutorials/dogsapi.mdx`:
- Around line 186-188: The wrapper function getBreedList currently calls
GetBreedList() but does not return its promise, causing init()'s .then(...) to
operate on undefined; update getBreedList to return the promise from
GetBreedList() (i.e., add a return before calling GetBreedList()) so init() can
chain correctly and the breed list loads as expected.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1905ae9f-9185-4aa5-8574-217903712120

📥 Commits

Reviewing files that changed from the base of the PR and between 77c2a06 and 5d5f06f.

📒 Files selected for processing (2)
  • website/docs/tutorials/dogsapi.mdx
  • website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx

Comment on lines 186 to 188
function getBreedList() {
GetBreedList().then((result) => (breeds = result));
GetBreedList();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Return the promise from getBreedList().

init() uses .then(...) on Line 171, but this wrapper drops the GetBreedList() promise. The documented app will throw on startup instead of loading the breed list.

💡 Proposed fix
  function getBreedList() {
-    GetBreedList();
+    return GetBreedList();
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function getBreedList() {
GetBreedList().then((result) => (breeds = result));
GetBreedList();
}
function getBreedList() {
return GetBreedList();
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@website/docs/tutorials/dogsapi.mdx` around lines 186 - 188, The wrapper
function getBreedList currently calls GetBreedList() but does not return its
promise, causing init()'s .then(...) to operate on undefined; update
getBreedList to return the promise from GetBreedList() (i.e., add a return
before calling GetBreedList()) so init() can chain correctly and the breed list
loads as expected.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@website/docs/tutorials/dogsapi.mdx`:
- Around line 256-257: Update the user-facing sentence that reads "To compile
the application to a single, production grade binary, run `wails build`." by
hyphenating the compound adjective to "production-grade" so it becomes "To
compile the application to a single, production-grade binary, run `wails
build`."; locate and edit the exact string in the dogsapi.mdx content where that
sentence appears.
- Around line 95-96: The three functions GetRandomImage, GetBreedList, and
GetImageUrlsByBreed currently read the entire response with ioutil.ReadAll and
then json.Unmarshal, which swallows decode errors and uses the deprecated
ioutil; replace each pattern with
json.NewDecoder(response.Body).Decode(&destStruct) and return or handle the
returned error directly (e.g., if err :=
json.NewDecoder(response.Body).Decode(&result); handleError(err)), and remove
the "io/ioutil" import from the file.

In `@website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx`:
- Around line 256-257: Change the phrase "production grade" to the hyphenated
compound adjective "production-grade" in the sentence that reads 'To compile the
application to a single, production grade binary, run `wails build`' so the
user-facing docs copy uses the correct hyphenation; update the sentence
containing `wails build` accordingly.
- Around line 95-96: Replace the pattern that reads the whole response with
ioutil.ReadAll and ignores json.Unmarshal errors in the tutorial functions
GetRandomImage, GetBreedList, and GetImageUrlsByBreed: instead use
json.NewDecoder(response.Body).Decode(&dst) directly on the response body and
check the returned error (passing it to handleError or returning it) so JSON
decoding failures aren’t swallowed; also remove the now-deprecated ioutil
import. Locate the decoding logic in GetRandomImage, GetBreedList, and
GetImageUrlsByBreed and swap the ReadAll+Unmarshal sequence for
json.NewDecoder(response.Body).Decode with proper error handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 89d7d733-e5bf-4856-b431-e862c26058bc

📥 Commits

Reviewing files that changed from the base of the PR and between 5d5f06f and 4b31f54.

📒 Files selected for processing (2)
  • website/docs/tutorials/dogsapi.mdx
  • website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx

Comment on lines 95 to +96
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
handleError(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify both tutorial copies still use the old read/decode pattern.
rg -n -C2 'ioutil|json\.Unmarshal' website/docs/tutorials/dogsapi.mdx website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx

Repository: wailsapp/wails

Length of output: 4622


Replace all three occurrences of ioutil.ReadAll + json.Unmarshal with json.NewDecoder().Decode() to properly handle decode errors.

The tutorial currently drops the json.Unmarshal error in three functions (GetRandomImage, GetBreedList, GetImageUrlsByBreed). When the API responds with malformed or non-JSON data, the sample app silently falls back to zero-values. Replace the pattern with json.NewDecoder(response.Body).Decode(...), which captures errors properly and removes the deprecated ioutil.ReadAll usage.

Apply this change at lines 95–99, 111–115, and 133–137, and remove the "io/ioutil" import.

Proposed fix (applies to all three functions)
 import (
 	"context"
 	"fmt"
 	"encoding/json"
-	"io/ioutil"
 	"log"
 	"net/http"
 	"sort"
 )
@@
-	responseData, err := ioutil.ReadAll(response.Body)
-	handleError(err)
-
 	var data RandomImage
-	json.Unmarshal(responseData, &data)
+	err = json.NewDecoder(response.Body).Decode(&data)
+	handleError(err)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@website/docs/tutorials/dogsapi.mdx` around lines 95 - 96, The three functions
GetRandomImage, GetBreedList, and GetImageUrlsByBreed currently read the entire
response with ioutil.ReadAll and then json.Unmarshal, which swallows decode
errors and uses the deprecated ioutil; replace each pattern with
json.NewDecoder(response.Body).Decode(&destStruct) and return or handle the
returned error directly (e.g., if err :=
json.NewDecoder(response.Body).Decode(&result); handleError(err)), and remove
the "io/ioutil" import from the file.

Comment on lines +256 to +257
To compile the application to a single, production grade binary, run
`wails build`.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Hyphenate "production-grade".

This is user-facing documentation text, so the compound adjective should be hyphenated.

✏️ Proposed fix
-To compile the application to a single, production grade binary, run
+To compile the application to a single, production-grade binary, run
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
To compile the application to a single, production grade binary, run
`wails build`.
To compile the application to a single, production-grade binary, run
`wails build`.
🧰 Tools
🪛 LanguageTool

[grammar] ~256-~256: Use a hyphen to join words.
Context: ... the application to a single, production grade binary, run wails build.

(QB_NEW_EN_HYPHEN)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@website/docs/tutorials/dogsapi.mdx` around lines 256 - 257, Update the
user-facing sentence that reads "To compile the application to a single,
production grade binary, run `wails build`." by hyphenating the compound
adjective to "production-grade" so it becomes "To compile the application to a
single, production-grade binary, run `wails build`."; locate and edit the exact
string in the dogsapi.mdx content where that sentence appears.

Comment on lines 95 to +96
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
handleError(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify both tutorial copies still use the old read/decode pattern.
rg -n -C2 'ioutil|json\.Unmarshal' website/docs/tutorials/dogsapi.mdx website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx

Repository: wailsapp/wails

Length of output: 4622


Replace ioutil.ReadAll + unhandled json.Unmarshal with json.NewDecoder().Decode() in tutorial examples.

The three code snippets in GetRandomImage(), GetBreedList(), and GetImageUrlsByBreed() currently read the entire response body and silently ignore JSON unmarshaling errors, leaving zero-values in the data. Use json.NewDecoder(response.Body).Decode() instead, which is cleaner, handles errors properly, and removes the deprecated ioutil import.

Proposed pattern
 import (
 	"context"
 	"fmt"
 	"encoding/json"
-	"io/ioutil"
 	"log"
 	"net/http"
 	"sort"
 )
@@
-	responseData, err := ioutil.ReadAll(response.Body)
-	handleError(err)
-
 	var data RandomImage
-	json.Unmarshal(responseData, &data)
+	err = json.NewDecoder(response.Body).Decode(&data)
+	handleError(err)

Apply to lines 95–96, 111–112, and 133–134.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx` around lines 95
- 96, Replace the pattern that reads the whole response with ioutil.ReadAll and
ignores json.Unmarshal errors in the tutorial functions GetRandomImage,
GetBreedList, and GetImageUrlsByBreed: instead use
json.NewDecoder(response.Body).Decode(&dst) directly on the response body and
check the returned error (passing it to handleError or returning it) so JSON
decoding failures aren’t swallowed; also remove the now-deprecated ioutil
import. Locate the decoding logic in GetRandomImage, GetBreedList, and
GetImageUrlsByBreed and swap the ReadAll+Unmarshal sequence for
json.NewDecoder(response.Body).Decode with proper error handling.

Comment on lines +256 to +257
To compile the application to a single, production grade binary, run
`wails build`.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Hyphenate "production-grade".

This is user-facing docs copy, so the compound adjective should be hyphenated.

✏️ Proposed fix
-To compile the application to a single, production grade binary, run
+To compile the application to a single, production-grade binary, run
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
To compile the application to a single, production grade binary, run
`wails build`.
To compile the application to a single, production-grade binary, run
`wails build`.
🧰 Tools
🪛 LanguageTool

[grammar] ~256-~256: Use a hyphen to join words.
Context: ... the application to a single, production grade binary, run wails build.

(QB_NEW_EN_HYPHEN)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@website/versioned_docs/version-v2.11.0/tutorials/dogsapi.mdx` around lines
256 - 257, Change the phrase "production grade" to the hyphenated compound
adjective "production-grade" in the sentence that reads 'To compile the
application to a single, production grade binary, run `wails build`' so the
user-facing docs copy uses the correct hyphenation; update the sentence
containing `wails build` accordingly.

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.

1 participant